3

when using python requests am I supposed to urlencode the URI manually?

>>> requests.get('http://example.com/increased by 10% (@tom)').url
u'http://example.com/increased%20by%2010%%20(@tom)'

here the %, (, ) and @ characters are not encoded while spaces are. what is the official way of making such request? should I wrap the path part using urllib.quote()?

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
Antony
  • 53
  • 6
  • have a look at http://stackoverflow.com/questions/5607551/python-urlencode-string question. In that there is method called urllib.quote_plus. See if that one works for you :) – Gunjan Sep 25 '15 at 06:36

1 Answers1

1

requests will quote only unreserved characters (code). % and () are reserved characters so you'd have to quote them yourself. Spaces are unreserved characters and requests does quote them for you. See Percent-encoding for the list of reserved URI characters.

Bernhard
  • 8,583
  • 4
  • 41
  • 42
  • The wiki page probably isn't something you can rely on, but since you're referencing it: I don't see the space-character being a reserved character. Am I missing something? – Caramiriel Sep 24 '15 at 14:30
  • Indeed and since it is *not* a reserved character, requests encodes/quotes it to %20. – Bernhard Sep 24 '15 at 14:41