Python – How solve python requests error: “Max retries exceeded with url”

pythonpython-requests

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!

Best Answer

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