json解码错误期望值

时间:2018-05-17 17:18:10

标签: python json

我真的需要帮助了解此错误的含义。 一切都运行得非常好几个小时,但随后就会弹出一个停止。我在网上得到了这个项目,我已经花了几天时间修复其他错误,并试图改变一些东西以满足我的需求但是,我对此非常陌生。

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)

我认为这是python文件中给我带来麻烦的部分。

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 个答案:

答案 0 :(得分:0)

服务器可能限制了你的速度。您应该将响应保存到变量并检查状态,而不是直接调用.json()调用.get()的结果:

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