10月09, 2019

How to solve this problem: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

show message first:

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

reasons:

#1. non-JSON conforming quoting

#2. XML/HTML output (that is, a string starting with <), or

#3. incompatible character encoding Ultimately the error tells you that at the very first position the string already doesn't conform to JSON.

As such, if parsing fails despite having a data-body that looks JSON like at first glance, try replacing the quotes of the data-body:

just print the json string you will see that problem.

本文链接:https://harry.ren/post/jsondecodeerror.html

-- EOF --

Comments