Parsing Values In Params Argument To Request.get() Which Contain Periods
I am using the python package requests to make a get request to a server. My goal is to replicate certain known http requests and incorporated them into my python script. The ori
Solution 1:
Note that .
is a perfectly valid character in a URL-encoded value.
You'd need to encode the values yourself, bypassing the standard encoding. I'd use urllib.urlencode()
, then replace the .
characters by %2E
by hand.
You then have to append the encoded string as a query parameter to the URL, and configure requests
to not re-encode the values:
params = {
'version'='0.12',
'language'='en',
...
}
params = urllib.urlencode(params)
params = params.replace('.', '%2E')
resp = requests.get('?'.join(url, params), config={'encode_uri': False})
The encode_uri
parameter set to False
does the trick here; it's this requests
default that otherwise will re-encode the whole URL to ensure RFC compliancy.
Post a Comment for "Parsing Values In Params Argument To Request.get() Which Contain Periods"