Search code examples
pythonurl-encodingurllib3

How to encode whitespaces as '+' in the url using urllib3?


I'm using urllib3 on Python 2.7. I need to send a request to a website that gives the desired response only when the spaces are separated by '+' and not by '%2b'.

http = urllib3.PoolManager()
var = 'foo bar'
url = 'https://foo.com/release?q=' + var
webdata = http.request('GET', url)

How can I do this in urllib3?


Solution

  • import urllib
    print(urllib.quote_plus('Hello world'))
    

    Hello+world