Python Forum
Error message wrong??? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Error message wrong??? (/thread-12796.html)



Error message wrong??? - Transylvania - Sep-13-2018

First of all, my English is poor. So please forgive me.

I was coding with python3. Specific version → Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
when I used 'urllib.parse.unquote' to unquote data, it throw a exception like this:
Error:
Error: Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> parse.unquote(bytes_test) File "D:\Python3\lib\urllib\parse.py", line 609, in unquote if '%' not in string: TypeError: a bytes-like object is required, not 'str'
In my understanding, this message told me: "I need a 'bytes-like object' but you give me a 'str'. So it's wrong."
So I tried to make the variable to 'bytes-like object', but it did not work.
In the end, I found that this function actually needed a 'str' but not a 'bytes-like object'.
Is this error message wrong? Or I just misunderstand what it means. Huh Huh Huh


RE: Error message wrong??? - stranac - Sep-13-2018

The error is referring to the if '%' not in string: part, which is in urllib code, so it is correct.

I do agree that it would probably be less confusing if the error was thrown when calling the function with a wrong type, instead of it happening when the function was already being executed...


RE: Error message wrong??? - Transylvania - Sep-13-2018

(Sep-13-2018, 09:22 AM)stranac Wrote: The error is referring to the if '%' not in string: part, which is in urllib code, so it is correct.

I do agree that it would probably be less confusing if the error was thrown when calling the function with a wrong type, instead of it happening when the function was already being executed...

I see, thanks~~ Smile