【问题标题】:How to get the error code from requests.exceptions.ChunkedEncodingError如何从 requests.exceptions.ChunkedEncodingError 获取错误代码
【发布时间】:2020-09-18 14:05:54
【问题描述】:

我有时会收到此错误。

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

【问题讨论】:

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


    【解决方案1】:

    您可以尝试以下方法吗:

    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
    

    【讨论】:

    • 哦!我会试试的,很快就会告诉你!谢谢!
    • @체라치에 您好,如果此解决方案对您有用,您能否接受答案?
    猜你喜欢
    • 2013-10-17
    • 2018-07-28
    • 2018-11-16
    • 2023-03-22
    • 2017-10-12
    • 2021-09-06
    • 2013-05-01
    • 2020-04-05
    • 2013-01-30
    相关资源
    最近更新 更多