Connection Error

Hello, while my program was running, I suddenly got the error you see below. What is the reason of this?

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\urllib3\connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "C:\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Anaconda3\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "C:\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "C:\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "C:\Anaconda3\lib\site-packages\urllib3\connection.py", line 353, in connect
    conn = self._new_conn()
  File "C:\Anaconda3\lib\site-packages\urllib3\connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000001F740E1AD90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.binance.com', port=443): Max retries exceeded with url: /api/v3/ping (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001F740E1AD90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Yunus/PycharmProjects/kripthon_wb/main.py", line 38, in <module>
    client = Client(config.api_key, config.api_secret)
  File "C:\Anaconda3\lib\site-packages\binance\client.py", line 300, in __init__
    self.ping()
  File "C:\Anaconda3\lib\site-packages\binance\client.py", line 526, in ping
    return self._get('ping', version=self.PRIVATE_API_VERSION)
  File "C:\Anaconda3\lib\site-packages\binance\client.py", line 371, in _get
    return self._request_api('get', path, signed, version, **kwargs)
  File "C:\Anaconda3\lib\site-packages\binance\client.py", line 334, in _request_api
    return self._request(method, uri, signed, **kwargs)
  File "C:\Anaconda3\lib\site-packages\binance\client.py", line 314, in _request
    self.response = getattr(self.session, method)(uri, **kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.binance.com', port=443): Max retries exceeded with url: /api/v3/ping (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001F740E1AD90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

If the line of code that caused the program to fail,

client = Client(config.api_key, config.api_secret)

If the above line is.

while True:
	try:
		client = Client(config.api_key, config.api_secret)

		if len(client ) > 0:
			break

	except Exception as e:
		print("Error:", e)
		time.sleep(5)
		pass

Would putting it inside a loop like this with try except blocks fix the problem?

Seems like you may have a connection issue.

Manually ping the API to confirm a connection is possible between your machine and the server. https://api.binance.com/api/v3/ping

Many thanks @tantialex . I am facing the same issue and was wondering if you could elaborate on your answer. What could be the reason for the connection issue? High volatility? Also, could you help me with the ‘Max retries exceeded with url’ part of the message? I checked and my request weight is way less than the 2400/min limit.

I am facing the same issue and was wondering if you could elaborate on your answer.

When diagnosing network issues, it’s best to remove as many intermediate steps as possible. Manually hitting the PING endpoint and looking at the raw response can help us better understand the issue.

What could be the reason for the connection issue? High volatility?

While it is possible for the service to suffer downtime in the case of high volatility it is a very rare occurrence and not the case for the original poster’s issue. It is most likely due to network issues between the client and the server.

Also, could you help me with the ‘Max retries exceeded with url’ part of the message? I checked and my request weight is way less than the 2400/min limit.

This is an error thrown by the library used to establish a connection with the server. The library failed to open a connection and performed a number of retries none of which worked. Once the retry limit was hit, the library seized retrying to connect and threw the error as to avoid a possible never ending loop.


That said, as mentioned previously, I suggest manually calling the PING endpoint and sharing the RAW response received from the API service.