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: [doc] urllib.parse.parse_qsl different results after urllib.parse.unquote
Type: behavior Stage:
Components: Documentation Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Alex.Vaystikh, docs@python, orsenthil, r.david.murray
Priority: normal Keywords:

Created on 2014-10-12 13:56 by Alex.Vaystikh, last changed 2022-04-11 14:58 by admin.

Messages (4)
msg229144 - (view) Author: Alex Vaystikh (Alex.Vaystikh) Date: 2014-10-12 13:56
parsing query-string before and after cleaning with urllib.parse.unquote can have very different results: http://nbviewer.ipython.org/gist/bornio/e112e6d8d04dfed898c8

Perhaps it should be better documented, or make the method more idempotent?
msg229156 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-12 14:56
Isn't it obvious that you have to parse before you unquote?  That's the purpose of quoting, after all.  I suppose that is one of those "beginner mind" things that is obvious only because I'm an experienced programmer...and that there are web servers that do it wrong. 

The docs could definitely use some improvement, since they don't mention that parse_qs automatically unquotes the values...it is implicit in the fact that urlencode with doseq=true is the inverse, and it encodes them, but it should be made explicit.

You also might want to take note of the 'keep_blank_values' attribute, which could also use a doc improvement (it isn't obvious from the text what 'blank values' are):

>>> parse_qs('a=1&b=2&b=1&a%3Donly_appears_after_unquote', keep_blank_values=True)
{'a': ['1'], 'b': ['2', '1'], 'a=only_appears_after_unquote': ['']}
msg229157 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-12 14:59
Eh, that "Isn't it obvious" comment was uncalled for.  Of course it isn't obvious, especially when the docs are unclear.
msg229169 - (view) Author: Alex Vaystikh (Alex.Vaystikh) Date: 2014-10-12 15:29
It is much clearer after your insight:
- I wasn't aware that 'parse_qs' unquotes values. That's most helpful!
- I had no idea what 'keep_blank_values' were before your example, but now it couldn't be more obvious. I know that adding that example to docs would've helped me a lot! Maybe others?

Thank you for the help!
History
Date User Action Args
2022-04-11 14:58:09adminsetgithub: 66808
2021-11-28 13:08:56iritkatrielsettitle: urllib.parse.parse_qsl different results after urllib.parse.unquote -> [doc] urllib.parse.parse_qsl different results after urllib.parse.unquote
versions: + Python 3.11, - Python 2.7, Python 3.4, Python 3.5
2014-10-12 15:29:56Alex.Vaystikhsetmessages: + msg229169
2014-10-12 14:59:44r.david.murraysetmessages: + msg229157
2014-10-12 14:56:53r.david.murraysetversions: + Python 2.7, Python 3.5
nosy: + docs@python, r.david.murray

messages: + msg229156

assignee: docs@python
components: + Documentation, - Library (Lib)
2014-10-12 13:56:59Alex.Vaystikhsettype: behavior
2014-10-12 13:56:21Alex.Vaystikhcreate