maybe this can be done more easily using urllib.urlencode?

http://docs.python.org/2/library/urllib.html#urllib.urlencode

http://stackoverflow.com/questions/3542881/python-opposite-function-urllib-urlencode