Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python requests and percent encoding of path

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()?

like image 215
Antony Avatar asked Dec 28 '25 02:12

Antony


1 Answers

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.

like image 78
Bernhard Avatar answered Dec 30 '25 15:12

Bernhard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!