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.

Title: Misleading error message in urllib.parse.unquote
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6
Status: closed Resolution: duplicate
Dependencies: Superseder: urllib.parse.unquote raises incorrect errormessage when string parameter is bytes
View: 32498
Assigned To: Nosy List: r.david.murray, thet, xtreak
Priority: normal Keywords:

Created on 2018-06-12 18:02 by thet, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg319396 - (view) Author: Johannes Raggam (thet) Date: 2018-06-12 18:02
urllib.parse.unquote gives an misleading error message when:

>>> import urllib
>>> urllib.parse.unquote(b'bytesurl')
*** TypeError: a bytes-like object is required, not 'str'


>>> urllib.parse.unquote('texturl')

The correct behavior is to pass a string/text object to unquote. But passing a bytes object gives a misleading error message.

A fix would be to add an assertion in like:

>>> assert isinstance(string, str)
msg319397 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-06-12 18:11
We don't generally do type checks like that.  This is a specific case of a general issue with binary operators and mismatched string/bytes types.  I thought there was an open issue for it, but I haven't found it yet.
msg319805 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-06-17 06:03
@r.david.murray I googled the error message and I hope you are referring to the below issue which has a patch and test.

issue :
msg319813 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-06-17 13:03
I thought there was a more general issue for the 'in' operator itself, but perhaps the issue you found was indeed the one I was thinking of.  This one certainly seems to be a duplicate of that one ;)  If you've a mind to, you could turn the patch in that issue into a PR to move the issue forward.
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 78027
2018-06-17 13:03:59r.david.murraysetstatus: open -> closed
superseder: urllib.parse.unquote raises incorrect errormessage when string parameter is bytes
messages: + msg319813

resolution: duplicate
stage: resolved
2018-06-17 06:03:06xtreaksetnosy: + xtreak
messages: + msg319805
2018-06-12 18:11:48r.david.murraysetnosy: + r.david.murray
messages: + msg319397
2018-06-12 18:02:33thetcreate