Python Requests TimeoutError: [WinError 10060] A connection attempt failed

Requests TimeoutError: [WinError 10060] A connection attempt failed

A connection attempt fails when the connected party do not properly respond after a period of time, or established connection fails because connected host has failed to respond.

The request that we made waits for a specified period of time or maximum number of retries to get the response. But if no response comes within the limited time or retries, TimeoutError is thrown.

Example Stack Trace

An example trace of this error looks like as shown in the following.

Traceback (most recent call last):
  File "C:\Users\PythonExamples\AppData\Roaming\Python\Python37\site-packages\urllib3\connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "C:\Users\PythonExamples\AppData\Roaming\Python\Python37\site-packages\urllib3\util\connection.py", line 80, in create_connection
    raise err
  File "C:\Users\PythonExamples\AppData\Roaming\Python\Python37\site-packages\urllib3\util\connection.py", line 70, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Solution

To fix this issue, make sure that your server is up and responds within the limited time or maximum retries from the client.