我在图书馆的帮助下打了一个电话
import time
def retry_on_connection_errors(url, data):
# data consists of dictionary with 20+ key value pairs
retries = 0
while retries < 5:
try:
response = requests.post(
url,
json=data,
verify=False,
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"}
)
return response
except:
retries += 1
time.sleep(1)
raise Exception("Maximum retries exceeded")
即使重试5次,也会出现错误
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
及
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
我正在使用python 3.7和请求2.24.0
调查了这个答案,但没有帮助: Python HTTP Server/Client: Remote end closed connection without response error
目前没有回答
相关问题 更多 >
编程相关推荐