json Decode error expecting value

我们两清 提交于 2021-02-11 13:27:59

问题


I really need help understanding what this error means. Everything runs perfectly fine for a couple of hours but then this pops up an it stops. I got this project online and I've already spent days fixing other errors and trying to change things to fit my needs but, i'm extremely new to this.

May 17 00:45:29 raspberrypi rc.local[393]:     response=requests.get("https://beta.todoist.com/API/v8/tasks", params={"token":TODOIST_TOKEN}).json()

May 17 00:45:29 raspberrypi rc.local[393]:   File "/usr/lib/python2.7/dist-packages/requests/models.py", line 850, in json

May 17 00:45:29 raspberrypi rc.local[393]:     return complexjson.loads(self.text, **kwargs)

May 17 00:45:29 raspberrypi rc.local[393]:   File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 516, in loads

May 17 00:45:29 raspberrypi rc.local[393]:     return _default_decoder.decode(s)

May 17 00:45:29 raspberrypi rc.local[393]:   File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 374, in decode

May 17 00:45:29 raspberrypi rc.local[393]:     obj, end = self.raw_decode(s)

May 17 00:45:29 raspberrypi rc.local[393]:   File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 404, in raw_decode

May 17 00:45:29 raspberrypi rc.local[393]:     return self.scan_once(s, idx=_w(s, idx).end())

May 17 00:45:29 raspberrypi rc.local[393]: simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I think this is the part of the python file that's giving me trouble.

def is_todo_changed():
response=requests.get("https://beta.todoist.com/API/v8/tasks", params={"token":TODOIST_TOKEN}).json()
global todolist_items
get_todolist_items= len (response)

if(get_todolist_items!=todolist_items):
    print('items changed')
    return True

response=requests.get("https://beta.todoist.com/API/v8/tasks", params={"token":TODOIST_TOKEN}).json()
data=response
global todolist_items
todolist_items=len(data)

回答1:


The server is probably rate-limiting you. Rather than calling .json() directly on the result of calling .get(), you should save the response to a variable and check the status:

response = requests.get(...)
if response.status_code == 200:
    data = response.json()


来源:https://stackoverflow.com/questions/50397154/json-decode-error-expecting-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!