from collections import OrderedDict
initial_url = 'http://www.stackoverflow.com'
search = 'Generate+value'
query_string = urlencode(OrderedDict(data=initial_url, search=search))
Build query string using urlencode python