|
发表于 2024-4-15 11:01:21
|
显示全部楼层
这个错误是因为变量`j`的值是`None`,而`None`类型是不可迭代的。所以在使用`for`循环遍历`j`时会报错。
要解决这个问题,你可以在遍历`response.json()`之前,添加一个判断语句来检查`response.json()`的返回值是否为`None`。如果为`None`,则跳过当前的循环。
下面是修改后的代码:
- while True:
- try:
- response = requests.post(url, headers=headers, data=data, verify=False)
- json_data = response.json()
- if json_data is not None:
- for j in json_data:
- if j is not None:
- for m in j:
- data = {
- "projectId": i,
- "buildingId": j,
- "unitId": m
- }
- while True:
- try:
- response = requests.post(url, headers=headers, data=data, verify=False)
- response.json()
- break
- except:
- # 处理请求异常的代码
- pass
- break
- except:
- # 处理请求异常的代码
- pass
复制代码
希望这个解答对你有帮助!如果还有其他问题,请随时提问。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|