Issue 33846: Misleading error message in urllib.parse.unquote (original) (raw)
Issue33846
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' while: >>> urllib.parse.unquote('texturl') 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 https://github.com/python/cpython/blob/0250de48199552cdaed5a4fe44b3f9cdb5325363/Lib/urllib/parse.py#L614 like: >>> assert isinstance(string, str) | ||
msg319397 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
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) * ![]() |
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 : https://bugs.python.org/issue32498 | ||
msg319813 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
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. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:01 | admin | set | github: 78027 |
2018-06-17 13:03:59 | r.david.murray | set | status: open -> closedsuperseder: urllib.parse.unquote raises incorrect errormessage when string parameter is bytesmessages: + resolution: duplicatestage: resolved |
2018-06-17 06:03:06 | xtreak | set | nosy: + xtreakmessages: + |
2018-06-12 18:11:48 | r.david.murray | set | nosy: + r.david.murraymessages: + |
2018-06-12 18:02:33 | thet | create |