Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Error 104, connection reset by peer

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 pip.

like image 271
xandermonkey Avatar asked Jan 24 '17 16:01

xandermonkey


People also ask

What is error 104 reset by peer?

It means that TCP reset has been sent to your computer. This happens for example when web server is restarted due to configuration change. Usually you solve this problem by reloading web page or waiting few minutes for maintanance window to close.

What does Connection reset by peer mean Python?

An application gets a connection reset by peer error when it has an established TCP connection with a peer across the network, and that peer unexpectedly closes the connection on the far end.

What is a 104 error?

104. HTTP Status Code. HTTP 401 Unauthorized. Error Text. The username or password was not correct.


2 Answers

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)

# ...
like image 167
Valentin M Avatar answered Oct 20 '22 09:10

Valentin M


Run

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

or

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

to fix this issue.

like image 30
xandermonkey Avatar answered Oct 20 '22 08:10

xandermonkey