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

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

Looking at stack trace youve provided your error is caused by httplib.BadStatusLine exception, which, according to docs, is:

Raised if a server responds with a HTTP status code that we don’t understand.

In other words something that is returned (if returned at all) by proxy server cannot be parsed by httplib that does actual request.

From my experience with (writing) http proxies I can say that some implementations may not follow specs too strictly (rfc specs on http arent easy reading actually) or use hacks to fix old browsers that have flaws in their implementation.

So, answering this:

Could it be a bad proxy?

… Id say – that this is possible. The only real way to be sure is to see what is returned by proxy server.

Try to debug it with debugger or grab packet sniffer (something like Wireshark or Network Monitor) to analyze what happens in the network. Having info about what exactly is returned by proxy server should give you a key to solve this issue.

Maybe you are overloading the proxy server by sending too much requests in a short period of time, you say that you got the proxy from a popular free proxy website which means that youre not the only one using that server and its often under heavy load.

If you add some delay between your requests like this :

from time import sleep


data=requests.get(url, proxies=proxy)
print data1
print {http: line}

(note the sleep(1) which pauses the execution of the code for one second)

Does it work ?

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

def hello(self):
    self.s = requests.Session()
    self.s.headers.update({User-Agent: self.user_agent})
    return True

Try this,It worked for me 🙂

Leave a Reply

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