SaltyCrane Blog — Notes on PythonJavascript and web development

How to escape (percent-encode) a URL with Python

import urllib

print urllib.quote_plus("")
print urllib.quote_plus("Kruder & Dorfmeister")


It is easy to be drawn to the urlencode function in the Python urllib module documentation. But for simple escaping, only quote_plus, or possibly quote is needed. I believe this is the appropriate solution to Python urlencode annoyance and O'Reilly's Amazon Hack #92.

For reference: Percent-encoding on Wikipedia


#1 xav commented on :

Nice music exemple :)

#2 Eliot commented on :

xav, it's not actually mine, but glad you liked it.

#3 Alvin Mites commented on :

Thank you for the sample - seems to pull fewer resources than a full urlencode