Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How solve python requests error: "Max retries exceeded with url"

I have the follow code:

res = requests.get(url)

I use multi-thread method that will have the follow error:

ConnectionError: HTTPConnectionPool(host='bjtest.com', port=80): Max retries exceeded with url: /rest/data?method=check&test=123 (Caused by : [Errno 104] Connection reset by peer)

I have used the follow method, but it still have the error:

s = requests.session()
s.keep_alive = False

OR

res = requests.get(url, headers={'Connection': 'close'})

So, I should how do it?

BTW, the url is OK, but it only can be visited internal, so the url have no problem. Thanks!

like image 801
thinkerou Avatar asked Feb 06 '17 02:02

thinkerou


2 Answers

you run your script on Mac? I also meet similar problem, you can execute ulimit -n to check how many files you can handle in a time.

you can use below to enlarge the configuration.

resource.setrlimit(resource.RLIMIT_NOFILE, (the number you reset,resource.RLIM_INFINITY))

hoping can help you.

my blog which associated with your problem

enter image description here

like image 109
Xun Lee Avatar answered Oct 10 '22 09:10

Xun Lee


I got a similar case, hopefully it can save some time to you:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /enroll/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f96ecc0>: Failed to establish a new connection: [Errno 61] Connection refused'))

The problem was actually silly... the localhost was down at port 8001! Restarting the server solved it.

like image 26
Rexcirus Avatar answered Oct 10 '22 08:10

Rexcirus