Python Error 104, connection reset by peer

后端 未结 2 1555
忘掉有多难
忘掉有多难 2020-12-15 01:42

I have been having this error when trying to make web requests to various hosts. After debugging a bit I have found the solution is updating the requests[security] through p

相关标签:
2条回答
  • 2020-12-15 01:48

    Run

    sudo python3 -m pip install "requests[security]"

    or

    sudo python -m pip install "requests[security]"

    to fix this issue.

    0 讨论(0)
  • 2020-12-15 01:57

    I was running into this issue as well with Python2.7 requests. Installing "requests[security]" with pip brought a clear improvement for me but out of 1000 requests in rapid succession, I would still get this error 2 or 3 times.

    Resolved to implementing retries as this seems to be a very temporary issue. Works like a charm now.

    import time
    import requests
    from requests.exceptions import ConnectionError
    
    # ...
    
    nb_tries = 10
    while True:
        nb_tries -= 1
        try:
            # Request url
            result = session.get("my_url")
            break
        except ConnectionError as err:
            if nb_tries == 0:
                raise err
            else:
                time.sleep(1)
    
    # ...
    
    0 讨论(0)
提交回复
热议问题