首页 > 解决方案 > 为什么我会收到此错误 - json.decode.JSONDecodeError:expecting value: line 1 clumn 1 (char 0)?

问题描述

我正在尝试将循环中每个结果的所有数据附加到一个 json 文件中。

这是我的代码:

for obj in all_psts: # There About 245 objs
    for i in range(1, 500):
        s = requests.Session()
        s.proxies = <my_proxy>
        resp = s.get("https://api/ur/{0}/recipients?page={1}".format(obj, i),
                     headers=header, verify=False).json()
        if resp: # If the page is not empty
            a = []
            a.extend(a)
            with open(pst_rec_path, 'w', encoding='utf-8', errors='ignore') as file:
                json.dump(a, file, ensure_ascii=False, indent=1, sort_keys=False, default=str)
        elif not resp: #if there is no data, stop the statement and run the next obj
            print('should stop and go to next obj')
            continue

但是我不断收到此错误消息:

 raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

关于为什么我不断收到此错误的任何想法或建议?

标签: pythonjsonpython-3.xpython-requests

解决方案


推荐阅读