close

[Solved] Python: requests.exceptions.ConnectionError. Max retries exceeded with url

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python: requests.exceptions.ConnectionError. Max retries exceeded with url in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python: requests.exceptions.ConnectionError. Max retries exceeded with url Error Occurs?

Today I get the following error Python: requests.exceptions.ConnectionError. Max retries exceeded with url in python.

How To Solve Python: requests.exceptions.ConnectionError. Max retries exceeded with url Error ?

  1. How To Solve Python: requests.exceptions.ConnectionError. Max retries exceeded with url Error ?

    To Solve Python: requests.exceptions.ConnectionError. Max retries exceeded with url Error What happened here is that itunes server refuses your connection (you're sending too many requests from same ip address in short period of time)

  2. Python: requests.exceptions.ConnectionError. Max retries exceeded with url

    To Solve Python: requests.exceptions.ConnectionError. Max retries exceeded with url Error What happened here is that itunes server refuses your connection (you're sending too many requests from same ip address in short period of time)

Solution 1

What happened here is that itunes server refuses your connection (you’re sending too many requests from same ip address in short period of time)

Max retries exceeded with url: /in/app/adobe-reader/id469337564?mt=8

error trace is misleading it should be something like “No connection could be made because the target machine actively refused it”.

There is an issue at about python.requests lib at Github, check it out here

To overcome this issue (not so much an issue as it is misleading debug trace) you should catch connection related exceptions like so:

try:
    page1 = requests.get(ap)
except requests.exceptions.ConnectionError:
    r.status_code = "Connection refused"

Another way to overcome this problem is if you use enough time gap to send requests to server this can be achieved by sleep(timeinsec) function in python (don’t forget to import sleep)

from time import sleep

All in all requests is awesome python lib, hope that solves your problem.

Solution 2

Just use requests' features:

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry


session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)

session.get(url)

This will GET the URL and retry 3 times in case of requests.exceptions.ConnectionErrorbackoff_factor will help to apply delays between attempts to avoid to fail again in case of periodic request quota.

Take a look at requests.packages.urllib3.util.retry.Retry, it has many options to simplify retries.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read