我有时会收到此错误。
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(10054, '현재 연결은 원격 호스트에 의해 강제로 끊겼습니다', None, 10054, None)", ConnectionResetError(10054, '현재 연결은 원격 호스트에 의해 강제로 끊겼습니다', None, 10054, None))
由于我看到了错误代码10054,因此我想使用这样的错误代码来处理此错误
try:
result = requests.get(url=url, **kwargs)
except requests.exceptions.ChunkedEncodingError as e:
#get the error code from e and then
if errorcode==10054:
#do something
我最初尝试过此方法,但它给了我另一个错误,那就是ChunkedEncodingError对象没有arg。
try:
result = requests.get(url=url, **kwargs)
except requests.exceptions.ChunkedEncodingError as e:
errorcode = e.arg[1]
if errorcode==10054:
#do something
最佳答案
您可以尝试以下方法:
try:
result = requests.get(url=url, **kwargs)
except requests.exceptions.ChunkedEncodingError as e:
#get the error code from e and then
if e.errno==10054:
#do something
关于python-3.x - 如何从requests.exceptions.ChunkedEncodingError获取错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62112460/