Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse blank to %20, not + ? #5170

Open
JFRabbit opened this issue Aug 20, 2019 · 2 comments

Comments

@JFRabbit
Copy link

commented Aug 20, 2019

If http param contains blank, how to parse blank to %20, not + ?

import requests

param = {
    "sql": "project = 'foo' and name = 'bar'"
}

res = requests.get(
    url='http://xxxx',
    params=param
)

print(res.url)
# actual    http://xxxx/?sql=project+%3D+%27foo%27+and+name+%3D+%27bar%27
# expect    http://xxxx/?sql=project%20%3D%20%27foo%27%20and%20name%20%3D%20%27bar%27

@nk521

This comment has been minimized.

Copy link

commented Aug 30, 2019

A quick dirty way to achieve that :

for x in param:
     param[x] = param[x].replace(" ","%20")

'+' or '%20', It shouldn't be an issue for you anyways

@epenet

This comment has been minimized.

Copy link

commented Aug 30, 2019

As far as I can work out, requests uses urllib.parse.urlencode.

By default, quote_plus() is used to quote the values, which means spaces are quoted as a '+' character and ‘/’ characters are encoded as %2F, which follows the standard for GET requests (application/x-www-form-urlencoded).

There seems to be a way to pass a "quote_via" parameter to the urlencode inside urllib, but that does not seem to be implemented in the requests library.

Can you explain why you would need this, as I have difficulty finding a reason for the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.