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

后端 未结 3 1388
情歌与酒
情歌与酒 2020-12-25 11:11

This is the script:

import requests
import json
import urlparse
from requests.adapters import HTTPAdapter

s = requests.Session()
s.mount(\'http://\', HTTPAd         


        
相关标签:
3条回答
  • 2020-12-25 11:36
    def hello(self):
        self.s = requests.Session()
        self.s.headers.update({'User-Agent': self.user_agent})
        return True
    

    Try this,It worked for me :)

    0 讨论(0)
  • 2020-12-25 11:39

    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 you're not the only one using that server and it's often under heavy load.

    If you add some delay between your requests like this :

    from time import sleep
    
    [...]
    
    data=requests.get(url, proxies=proxy)
    data1=data.content
    print data1
    print {'http': line}
    sleep(1)
    

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

    Does it work ?

    0 讨论(0)
  • 2020-12-25 11:43

    Looking at stack trace you've 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 aren't 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?

    ... I'd 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.

    0 讨论(0)
提交回复
热议问题