I have simple Bottle route, and URL should contain : (colon) sign. URL should be like /REST/item:128 or /REST/item:89753
My route is
#route('/REST/item:<id:int>')
def icc(id):
return { 'id': id }
Route is not working properly. id contain only last char from url id, not full id.
How to use : (colon) in route?
Wow, this was confusing.
I haven't had time to fully understand what's happening, but I suspect that one of Bottle's route regexes is eating too many characters when there's a colon in the route.
In any case, escaping the colon with a backslash appears to solve the problem:
#route(r'/REST/item\:<id_:int>') # note the "r" prefix there
def icc(id_):
return {'id': id_}
Here's a test request and its response:
=> curl -v 'http://127.0.0.1:8080/REST/item:123'
{"id": 123}
EDIT: Mystery solved.
Bottle currently supports two syntaxes for url wildcards: The
one (since 0.10) and the :old syntax. Both are described here:
http://bottlepy.org/docs/dev/routing.html
In your example, the : triggered the old syntax. The solution is to
escape the colon with a backslash (as described in the SO answer).
Escaping is fully implemented and works as intended, but is
undocumented. This is why I leave this issue open. Pull requests for
better documentation would be welcomed.
Related
Is anyone knows how Flutter URI encoding/decoding works?
I have one issue. Let me give you some background on the issue. We have one deep link which will give us the email and access token code to reset the password. We will validate the token on the front end and then allow users to do a reset.
Here is the sample URL from Firebase dynamic link
https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com
Firebase dynamic link will give us this URL in the URI object. The issue is when I try to fetch the query params from this URI object, it removes plus sign from an email and replaces it with the space character instead. E-mail should same as displayed in the above link. This is the email received when I fetch query params: test abc#xyz.com
I have created two dart pads to figure out the issue. Here is the 1st sample where I am parsing (since firebase dynamic link is doing the same) the URL into the URI object and tried printing the output. As expected it removes the plus sign.
Code:
main() {
var httpsUri = Uri.parse("https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com");
print(httpsUri.queryParameters);
}
Output:
{access_token: abcd, email: test abc#xyz.com}
In another sample, I tried creating the URI object from the same parameters and link but manually. Here is the code
Code:
main() {
var httpsUri = Uri(
scheme: 'https',
host: 'example.com',
path: '/auth/resetPassword/',
queryParameters: {
'access_token': 'abcd',
'email': 'test+abc#xyz.com'
});
print(httpsUri.queryParameters);
}
Output:
{access_token: abcd, email: test+abc#xyz.com}
If you see here, the email is correctly displayed.
My exact scenario is matching with the first sample code. Based on my findings it removes the plus sign due to encoding and decoding of the URL as a plus sign has a special meaning in the URL. But on the other hand why it is not happening in 2nd example?
Any help would be appreciated!
+ is a reserved character for URIs and therefore should be encoded to %2B if you want a literal + character.
But on the other hand why it is not happening in 2nd example?
Your second example works because it constructs a Uri object directly, and if you were to convert it to a String, it would perform necessary encodings for you. That is, print(httpsUri) would output:
https://example.com/auth/resetPassword/?access_token=abcd&email=test%2Babc%40xyz.com
rather than original (malformed) URL:
https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com
I'm sending Oven D' word into the search reqeust paramters.
If I'm passing static value (Oven D') into the post alamofire request it's working fine. The request of this paramter is like this
"Keyword" = "Oven D\'"
But if I'm sending it form searchBar.text then it will not work and my request is something like this
"Keyword" = "Oven D'"
Please suggest me why this happening. Is there I need to change something in Search bar property.
Thanks in Advance for suggesting or helping me to sort out this issue.
It was an issue of symbols entering from the search keyboard.
I'm entering ' this but actually it was technically entered , in upwords direction
I used following code and it works:
searchBar.text!.replacingOccurrences(of: "’", with: "'")
What's the right format for dateRange for rest-li v2?
The current examples in the documentation do not support it, and I don't understand from the rest-li documentation what's the format for it, exactly.
This is the request I make:
Headers:
X-Restli-Protocol-Version: 2.0.0
Authorization: Bearer <token-here>
URL (with request parameters):
https://api.linkedin.com/v2/adAnalyticsV2?q=analytics&pivot=CAMPAIGN&dateRange.start.day=1&dateRange.start.month=1&dateRange.start.year=2017&timeGranularity=DAILY
OR
URL - deconstructed (with request parameters):
Base URL:https://api.linkedin.com/v2
Params:
q:analytics
pivot:CAMPAIGN
dateRange.start.day:1
dateRange.start.month:1
dateRange.start.year:2017
timeGranularity:DAILY
Error I get:
{
"serviceErrorCode": 100,
"message": "Unpermitted fields present in PARAMETER: Data Processing >Exception while processing fields [/dateRange.start.day, /dateRange.start.month, >/dateRange.start.year]",
"status": 403
}
Note: I'm referred to a question with the same error in the comments, however this might be caused by a different reason, and the answer there does not work for me. If by StackOverflow's standards you still think that it's a duplicate, please let me know and I'll close this question.
The first solution didn't work for me. As Linkedin's API documentation is shit in regards to this it took me a lot of trial and error. #Gal-Grünfeld final structure is correct but the example isn't. Linkedin's docs say the key is dateRange.start which is wrong.
dateRange=(start:(day:1,month:9,year:2020))
Solution provided by one of the LinkedIn developers:
For Restli version 2, for parameter dateRange (tested only for endpoint AnalyticsV2):
rangeDate := (start[,end]) (end is optional)
start, end - type: Date
Date := (day, month, year)
day - type: integer (tested for single digit only)
month - type: integer (tested for single digit only)
year - type: integer (tested for 4 digits only)
Final structure (not including the optional end):
dateRange=(start:(day:,month:,year:))
Example:
dateRange=(start:1,month:1,year:2017)
When you are using Python and requests, the working format of 'dateRange' parameter is:
params = {
'q': 'analytics',
'dateRange.start.day': '1',
'dateRange.start.month': '1',
'dateRange.start.year': '2022',
'pivot': 'COMPANY',
'timeGranularity': 'DAILY'
}
But remember to remove (or not use at all) the header "X-Restli-Protocol-Version"
Be careful about the query parameter encoding, I am using Faraday library for HTTP get requests and it encodes the query string, so I am correctly using the dateRange=(start:(day:1,month:9,year:2020)), but at the end Faraday encodes it to something like this: dateRange%3D%28start%3A%28day%3A1%2Cmonth%3A9%2Cyear%3A2020%29%29. But linkedin expects the first brackets unencoded, I had same problem with other endpoint, where the List(something) was not working, but with curl it was working, the difference is encoding.
I use "Filedownload.save" to download files with Zk, but i have a problem.
Zk cut my filenames in some characters, for example, if the linema is "FISH#CHIPS.pdf", the file dowload as "FISH.pdf"
Anyone knows how to solve it?
UPDATE:
I have follow the instructions, and i finally see that the server response this JSON:
{"rs":[["download",["/myApp/zkau/view/z_aq5/dwnmed-3/son/FISH#CHIPS.pdf"]]],"rid":9}
And i am lost now, what do Zk with this JSON on the cliente side?
The official ZK-Bug is tracked as ZK-3809
A server side workaround is the following:
split download code such as ...
Filedownload.save("test content", "text/plain", "test#test.txt");
... into ...
AMedia media = new AMedia("test#test.txt", "txt", "text/plain", "test content");
Clients.response(new AuDownload((DeferredValue) () ->
Executions.getCurrent().getDesktop().getDownloadMediaURI(
media, "test#test.txt").replace("#", "%23")));
... allowing to encode special chars as needed.
UPDATE: ZK-3809 has been fixed and will be included in ZK version 8.5.1
The problem is that # is one of those "reserved characters" that, while valid in a URL, are treated in special ways. Look at this question for more details. My guess is that everything after the # is interpreted as a fragment on the page, and hence ignored in this case.
There are ways to fix this, for example by replacing # by %23. But doing this on the server side when calling Filedownload.save changes the filename to literally FISH%23CHIPS.pdf.
Instead, we can intercept the client side method that downloads the file when the response you showed arrives. This way, zk will still give the file its normal name, and only the download will sanitize the URL. Add this to a script tag or loaded js file:
zk.afterLoad('zk', function() {
var oldMethod = zAu.cmd0.download;
zAu.cmd0.download = function(filename) {
return oldMethod(filename.replace(new RegExp('#', 'g'), '%23'));
}
});
Then it will download the file with the complete name. You might want to take the extra time and sanitize the other reserved characters as well. Read this wiki article about "percent encoding" for the right codes.
I have also filed a support ticket with zk, I think this should be handled by the client side method out-of-the-box.
Now I am not sure it practical or not but I like to have a URL like this
http://example.com/field1_query:field2_query map but it seem like ASP.NET MVC Routing not happy with the ":" char here my route
routes.MapRoute("filter",
"{field1_query}:{field2_query}",
new { controller ="...", action="..."} );
It doesn't work but if I change to {field1_query}/{field2_query} it works fine (which mean my URL also change http://example.com/field1_query/field2_query).
The colon is a reserved character in a URL. See the IETF spec. You would need to escape any restricted or reserved characters.