Python Requests HTTPConnectionPool and Max retries exceeded with url

pythonpython-requests

On a Linux cluster, I get this error with Requests:

ConnectionError: HTTPConnectionPool(host='andes-1-47', port=8181): Max
retries exceeded with url: /jammy/api/v1 (Caused by : '')

What does this error mean? Is it a Requests problem or is it on the host, and what is the solution?

By the way, the program works successfully on both Windows and Linux standalone machines with localhost.

Best Answer

So the Max retries exceeded with url: ... bit can be vastly confusing. In all likelihood (since you mention that this works using localhost) that this is an application that you're deploying somewhere. This would also explain why the host name is andes-1-47 and not something most would expect (e.g., example.com). My best guess is that you need to either use the IP address for andes-1-47 (e.g., 192.168.0.255) or your linux cluster doesn't know how to resolve andes-1-47 and you should add it to your /etc/hosts file (i.e., adding the line: 192.168.0.255 andes-1-47).

If you want to see if your linux cluster can resolve the name you can always use this script:

import socket

socket.create_connection(('andes-1-47', 8181), timeout=2)

This will timeout in 2 seconds if you cannot resolve the hostname. (You can remove the timeout but it may take a lot longer to determine if the hostname is reachable that way.)