I have tried to follow the documentation but was not able to use urlparse.parse.quote_plus()
in Python 3
:
from urllib.parse import urlparse params = urlparse.parse.quote_plus({'username': 'administrator', 'password': 'xyz'})
I get
AttributeError: 'function' object has no attribute 'parse'
s = urllib2. quote(s) # URL encode. # Now "s" is encoded the way you need it. It works!
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.
You misread the documentation. You need to do two things:
Luckily urllib.parse.urlencode
does both those things in a single step, and that's the function you should be using.
from urllib.parse import urlencode, quote_plus payload = {'username':'administrator', 'password':'xyz'} result = urlencode(payload, quote_via=quote_plus) # 'password=xyz&username=administrator'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With