-3

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?

hitro
  • 5
  • 2
  • Use `urlencode` for this aims http://stackoverflow.com/questions/2506379/add-params-to-given-url-in-python – Dmitry Feb 28 '17 at 21:03

1 Answers1

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

Hello+world

Zroq
  • 8,002
  • 3
  • 26
  • 37
  • I was hoping to do it within urllib3 alone, which seem to encode it only the '%20' way. But this works as well, thanks! – hitro Mar 01 '17 at 07:15
  • You can't, unless you replace spaces im your string with plus signs. I would rather recommend you to use requests instead of any urllib package for simpler and a much more complete handset of functions. – Zroq Mar 01 '17 at 07:22