This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib.parse.urlencode encoding lists as strings
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: orsenthil, someone3x7
Priority: normal Keywords:

Created on 2011-06-23 03:02 by someone3x7, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg138850 - (view) Author: Joesph (someone3x7) Date: 2011-06-23 03:02
"""
Per the documentation urlencode is supposed to encode a structure returned by parse_qs back to a query string. However, urlencode appears to not be processing the lists associated with each key.
Example:
"""
import urllib.parse
dictQuery = urllib.parse.parse_qs('a=b&b=c&c=d&c=e',
                                  strict_parsing=True,
                                  encoding='iso8859-1')
assert isinstance(dictQuery,dict)
assert isinstance(dictQuery['a'],list)
strQuery = urllib.parse.urlencode(dictQuery, encoding='iso8859-1')
print(strQuery)
""" 
Outputs: a=%5B%27b%27%5D&c=%5B%27d%27%2C+%27e%27%5D&b=%5B%27c%27%5D
Which means: a=['b']&c=['d', 'e']&b=['c']
Expected: a=b&c=d&c=e&b=c
"""
msg138851 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-06-23 03:41
I see you missed the doseq parameter which is applicable in this case.

print(urllib.parse.urlencode(dictQuery, encoding='iso8859-1',doseq=True))
a=b&c=d&c=e&b=c
msg138856 - (view) Author: Joesph (someone3x7) Date: 2011-06-23 07:25
Hrm, yes. 'Tis what I get for working while sick.
msg138857 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-06-23 07:30
Joseph, resolution applies for the bug not the process. tc. :)
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56599
2011-06-23 07:30:20orsenthilsetresolution: accepted -> not a bug
messages: + msg138857
2011-06-23 07:25:24someone3x7setresolution: not a bug -> accepted
messages: + msg138856
2011-06-23 03:41:41orsenthilsetstatus: open -> closed

nosy: + orsenthil
messages: + msg138851

resolution: not a bug
2011-06-23 03:02:45someone3x7create