JSONDecodeError: Expecting value: line 1 column 1

后端 未结 2 738
无人共我
无人共我 2021-02-04 00:30

I am receiving this error in Python 3.5.1.

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here is my code:<

2条回答
  •  一生所求
    2021-02-04 01:06

    If you look at the output you receive from print() and also in your Traceback, you'll see the value you get back is not a string, it's a bytes object (prefixed by b):

    b'{\n  "note":"This file    .....
    

    If you fetch the URL using a tool such as curl -v, you will see that the content type is

    Content-Type: application/json; charset=utf-8
    

    So it's JSON, encoded as UTF-8, and Python is considering it a byte stream, not a simple string. In order to parse this, you need to convert it into a string first.

    Change the last line of code to this:

    info = json.loads(js.decode("utf-8"))
    

提交回复
热议问题