Terry J. Reedy <[email protected]> added the comment:
'urlencode()' is a TypeError as a query (dict) is needed. The claim is that
'/?' in a key are encoded but should not be. I verified the encoding in 3.10.
>>> urlencode({'/?link': 'pubmed'})
'%2F%3Flink=pubmed'
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote
and the following entry from 'quote_plus' say that by default, quote_via is
quote_plus and the latter quotes '/' and '?'. So the bug report as stated is
not valid.
---
They also say that passing 'quote_via=quote' should suppress quoting of '/',
because it defaults to 'safe='/', but it does not.
>>> urlencode({'/?link': 'pubmed'}, quote_via=quote)
'%2F%3Flink=pubmed'
So either the doc should be changed in 3 places, or the default safe for quote
should be '/' as documented.
---
Anh, use safe='/?' to get what you want.
>>> urlencode({'/?link': 'pubmed'}, quote_via=quote, safe='/?')
'/?link=pubmed'
----------
nosy: +orsenthil, terry.reedy
title: urllib.parse.urlencode() return wrong character -> urllib.parse.quote
uses safe='' as default
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46397>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com