python - 为什么我会收到此错误 - 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)
关于为什么我不断收到此错误的任何想法或建议?
解决方案
推荐阅读
- google-apps-script - 为谷歌电子表格中的特定标签运行脚本
- laravel - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException 编辑配置文件信息期间没有消息不断出现
- regex - 使用正则表达式匹配模式并存储到数组中
- node.js - 我应该在 package.json 中为“类型”字段使用什么值?
- openssl - 当我尝试将其转换为 cert.pem 和 key.pem 时,我有 p12 证书。Key.pem 为空
- typescript - 打字稿仅一种或另一种
- upc - 我应该在 UPC 中使用哪种网络类型
- powerbi - 无法在 Power BI 中建立一对多关系
- c# - 本地化只返回名称而不是资源文件中的值
- python - 狮身人面像超链接到以别名导入的 Python 模块的成员