How to encode a string for url param in python

python, urlencode

Solution

use urllib.quote_plus function. Here is an example:

#!/usr/bin/python

print "Content-Type: text/html;charset=utf-8";
print

import urllib

str = "Hello World?"
str = urllib.quote_plus(str)

print str

Output: Hello+World%3F

Problem

How can I encode a string so that I can pass the encoded string in url params?

Original source

Related problems