How To Solve Error “Max retries exceeded with URL” In Python

ConnectionError: Max retries exceeded with url

“ConnectionError: Max retries exceeded with url” is a common error in Python related to a connection error. The below explanations can help you know more about the cause of this error and solutions.

How does the error “Max retries exceeded with URL” happen?

“Max retries exceeded with URL” is a common error related to a connection error. You will encounter this situation while making requests using the requests library. 

This error indicates that the request could not be completed successfully. There can be no more connections since the server is overloaded. You need to verify that you can connect to the device causing the problems. There are five common cases:

  1. The host is not listening on the port given
  2. There are too many open HTTPconnections.
  3. There is not enough RAM on the computer.
  4. Another option is that the target website has blacklisted the IP as a result of the frequent requests.
  5. The requested URL is incorrect.

In general, the detailed error message should resemble the following output. The word “requests.exceptions.ConnectionError” normally appears at the beginning of an error message, informing us that something went wrong when the request was attempting to connect. There are hence no general solutions because it depends on your error message.

The exception “requests.exceptions.SSLError” can occasionally appear, which is obviously an SSL-related problem. The error comes with a longer message text, potentially something like this: Unable to establish a new connection: Connection rejected or [Errno -2] Unknown name or service are also errors. These messages allow us to further identify and address the problem.

[Errno 61] Connection refused


import requests	
response = requests.get("")

The fact that the website is not a secure HTTPS connection, and port 443 is of HTTPS, while port 80 is instead an HTTP one. One possible reason why this would happen is if the connection was attempted to port 443, but the host was not listening to it. In this case, consider listening on port 80 instead.

import requests	
response = requests.get("")

[Errno -2] Name or service not known


import requests
from lxml import html
page = requests.get("")
tree = html.fromstring(page.text)

Your connection is being denied by the LearnshareIT server at this time (you had sent too many requests from the same IP address in a short period of time). The error log can be understood as “The connection could not be established as the intended machine actively rejected it. To fix this, please read the two approaches below.

How to solve the error “Max retries exceeded with URL”?

Method 1: Let enough time between queries to the server

You must let enough time for queries to the server, which may be done using Python’s sleep() (time in sec) function (remember to import sleep)

import time
page = ''
while page == '':
        page = requests.get("")
        print("Error.Waiting 6s")
        print("Now try reconnecting")

Method 2: Disable SSL verification

Another way to fix this problem is to disable SSL verification.  You should also use try catch exceptions like 1st method to make sure not to send too many requests:

import requests
page = requests.get("", verify=False)


The error ConnectionError: Max retries exceeded with url occurs when too many failed requests have been made. To help with this situation, make sure you are connecting to the correct URL and remember to leave a sleep time for your requests before continuing to retry.

Maybe you are interested in similar errors:

Leave a Reply

Your email address will not be published. Required fields are marked *