python-3.x - 如何从requests.exceptions.ChunkedEncodingError获取错误代码

标签 python-3.x error-handling python-requests

我有时会收到此错误。

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/

相关文章:

python-3.x - Pandas:如何使用开始和结束时间戳分析数据?

python - with ... : for . .. : 在一行中

c# - Linq、错误提供程序、数据绑定(bind) : Custom error messages

Python 请求 - SAML 登录重定向

python - 请求库无法正确发布,但 urllib 成功 [python]

python-3.x - 为什么 github api 给我的 repo 星数较低?

Python 类型错误 : can only concatenate list (not "int") to list for Parkes error grid

twitter-bootstrap - 在 Bootstrap 模式中捕获 Firebase 错误

asp.net-core - 如何绕过 .NET Core 2.2 和 3.1 错误处理并显示标准 IIS 状态代码页?

python - Cloudscraper 返回 AttributeError : 'SSLContext' object has no attribute 'orig_wrap_socket'