How to encode url in Python?

I tried this: but it does not work.

print urllib.urlencode("http://"+SITE_DOMAIN+"/go/")

I want to turn it into a string with URL encodings

+5
source share
2 answers

Have you been looking for quote () or quote_plus () instead?

>>> urllib.quote("http://spam.com/go/")
'http%3A%2F%2Fspam.com%2Fgo%2F'
+11
source

You are looking for urllib.quote().

+1
source

All Articles