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.urlencode doesn't work for output from cgi.parse_qs
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: mike_j_brown, myers_carpenter
Priority: normal Keywords:

Created on 2003-10-30 22:39 by myers_carpenter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg18829 - (view) Author: Myers Carpenter (myers_carpenter) Date: 2003-10-30 22:39
>>>
urllib.urlencode(cgi.parse_qsl('ext=.jpg&outquality=56'))
'ext=.jpg&outquality=56'
>>>
urllib.urlencode(cgi.parse_qs('ext=.jpg&outquality=56'))
'ext=%5B%27.jpg%27%5D&outquality=%5B%2756%27%5D'

"%5B%27" = "['"

 
msg18830 - (view) Author: Mike Brown (mike_j_brown) Date: 2004-03-31 06:01
Logged In: YES 
user_id=371366

As per the urlencode() API documentation, you are passing in 
sequences, so you need to set the doseq flag.

>>> urllib.urlencode(cgi.parse_qs
('ext=.jpg&outquality=56'),doseq=1)
'ext=.jpg&outquality=56'

I recommend that this bug report be closed as Invalid.
msg18831 - (view) Author: Myers Carpenter (myers_carpenter) Date: 2004-03-31 16:56
Logged In: YES 
user_id=335935

Can you name one web app that you know will take args in the
form of "ext=[27.jpg]"?  Why not do some type inspection to
see what types you are dealing with?  What is the use of
encoding a list in a url using python syntax?
msg18832 - (view) Author: Mike Brown (mike_j_brown) Date: 2004-04-01 21:13
Logged In: YES 
user_id=371366

I am only guessing, here, but if you had an object that you 
wanted to embed a representation of in a URL or in HTML 
form data, it would be prudent to call str() on the object and 
let its __str__ method give you a string representation, and 
then you'd percent-encode that. This makes sense for user-
defined classes, where you can define __str__, but not for 
built-in types like an ordinary list, so they give you the doseq 
flag for those situations.
msg18833 - (view) Author: Myers Carpenter (myers_carpenter) Date: 2004-04-04 01:19
Logged In: YES 
user_id=335935

Ok... closing
History
Date User Action Args
2022-04-11 14:56:00adminsetgithub: 39479
2003-10-30 22:39:03myers_carpentercreate