[New-bugs-announce] [issue12390] urllib.parse.urlencode encoding lists as strings

Joesph report at bugs.python.org
Thu Jun 23 05:02:45 CEST 2011

New submission from Joesph <someone3x7 at gmail.com>:

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.
import urllib.parse
dictQuery = urllib.parse.parse_qs('a=b&b=c&c=d&c=e',
assert isinstance(dictQuery,dict)
assert isinstance(dictQuery['a'],list)
strQuery = urllib.parse.urlencode(dictQuery, encoding='iso8859-1')
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

components: Library (Lib)
messages: 138850
nosy: someone3x7
priority: normal
severity: normal
status: open
title: urllib.parse.urlencode encoding lists as strings
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list