Python Dict to Url Query String/Parameters (urlencode)

June 9, 2019

Python 2.x

from urllib import urlencode

data = {'name': 'Desmond Lua', 'age': 40}
query_string = urlencode(data)
name=Desmond+Lua&age=40

Python 3.x

from urllib.parse import urlencode

data = {'name': 'Desmond Lua', 'age': 40}
query_string = urlencode(data)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.