python - 中途接收到 int() 和 ChunkedEncodingError: ('Connection broken: IncompleteRead..') 的错误无效文字?
问题描述
我每天都在使用 API &requests 库以固定的节奏读取一些数据,直到最近一切正常。突然在读取数据中途出错:
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception, another exception occurred:
ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))
During handling of the above exception, another exception occurred:
ProtocolError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))
这不会偶尔发生。当我尝试读取数据时,我在..online 大约一个小时内收到此错误,我看到它与服务器/网络相关。但我不确定如何确认这一点或检查我是否无法解决它。
url = "https://api...."
dflist=[]
for i in range (0,variable1):
with open("/dbfs/tmp/file{}.json".format(i+1)) as f:
data = json.load(f)
data1=json.dumps(data)
payload=str(data).encode("utf-8")
headers = {
'content-type': "application/json; charset=utf-8",
'cache-control': "no-cache",
}
#response = requests.request("POST", url, data=payload, headers=headers)
with requests.request("POST", url, data=payload, headers=headers) as response:
print("RESPONSE: ", response)
for j in range(20):
geturl= str(response.text)
getresponse = requests.request("GET", geturl)
if getresponse.status_code!=200:
time.sleep(20)# wait 20 seconds
j=j+1
else:
jsondata=getresponse.text
jdata=json.loads(jsondata)
df=pd.DataFrame(jdata)
print("df length")
print(len(df))
dflist.append(df)
break
i=i+1
另外,如果有人可以就如何解决此类问题提供建议,我将不胜感激?我不经常使用 API 和 url 请求,所以不确定在这种情况下检查的基础知识
解决方案
推荐阅读
- oracle-apex - Oracle APEX - 如何确保在提交页面之前完成回调
- jquery - 将 Web Pack 输出为库
- sql - 结合数据透视表计算比率
- php - 是否可以在 Symfony 控制台中将参数作为命名空间传递?
- gitlab - 错误:合并失败:合并期间出现问题:3:US-ASCII 中的字节序列无效。请再试一次。在 GitLab 上
- matrix - 在 ThreeJS 中绘制镜像对象
- flutter - 在 Flutter 中将 JSON 作为字符串处理
- apache-flink - Beam WordCount TaskManagerFailure NoClassDefFoundError for MetricUpdates$MetricUpdate
- javascript - Deviantart 的 Greasemonkey/Tempermonkey 脚本
- python - 如何对具有n个元素的数组进行排序,其中k个元素在O(n + k log k)中不合适?