json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

Terry Reedy tjreedy at udel.edu
Mon May 9 19:07:38 EDT 2016


On 5/9/2016 3:56 PM, zljubisic at gmail.com wrote:
> Hi,
>
> in python3 my variable looks like this:
>
> a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
> str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''
>
> If I execute the following command I get the error:
>
>>>> json.loads(str(a))
> Traceback (most recent call last):
>   File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
>     exec(exp, global_vars, local_vars)
>   File "<input>", line 1, in <module>
>   File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads
>     return _default_decoder.decode(s)
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode
>     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in raw_decode
>     raise ValueError(errmsg("Expecting value", s, err.value)) from None
> ValueError: Expecting value: line 1 column 1 (char 0)
>
> Why I am getting this error?
> If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}' everything works as expected.

This means that the two versions of 'a' are not the same.  So what you 
should have done to debug is print the second to see what you actually 
passed to json.

Editorial: Programming classes should teach basic debugging better. I 
have seen numerous newbie Stackoverflow questions where the person 
should have started with adding a print statement before posting a question.

-- 
Terry Jan Reedy




More information about the Python-list mailing list