[Python-Dev] urllib.urlencode & repeated values

Guido van Rossum guido@digicool.com
Thu, 18 Jan 2001 11:28:12 -0500


> I'm pretty sure this has come up before, but urllib.urlencode doesn't handle
> repeated parameters properly.  If I call
> 
>     urllib.urlencode({"performers": ("U2","Lawrence Martin")})
> 
> instead of getting
> 
>     performers=U2&performers=Lawrence+Martin
> 
> I get a quoted stringified tuple:
> 
>     performers=%28%27U2%27%2c+%27Lawrence+Martin%27%29
> 
> Obviously, fixing this will change the function's current semantics, but I
> think it's worth treating lists and tuples (actually, any sequence) as
> repeated values.  If the existing semantics are deemed valuable enough, a
> third default parameter could be added to switch on the new behavior when
> desired.
> 
> If others agree I'd be happy to whip up a patch.  I think it's a bug.

Agreed.  If you can come up with something that supports all sequence
types, and treats singleton sequences the same as their one and only
item, it would even be the inverse of cgi.parse_qs()!

--Guido van Rossum (home page: http://www.python.org/~guido/)