[Solved] Python urlib2gaierror: [Errno 11004] getaddrinfo failed

Gaierror: get address info error. If the URL is incorrect or the proxy information is not configured correctly, this error will be reported

I wrote a very simple class to send HTTP requests. Sometimes it runs thousands of times without reporting an error. Sometimes it runs dozens of times without reporting the [11004] error at the beginning. Many tutorials have been found on the Internet, such as adding a disconnect mark on the header, or increasing the number of retries

So, it’s good to try again. If you find an error, sleep for two seconds and resend it

class HTTPsClient(object):
    def __init__(self, url):
        self.url = url
        self.session = requests.session()
    def send(self, data=None, **kwargs):
        flag = False
        while not flag:
                response = self.session.request(method='POST', url=self.url, data=data,**kwargs)
                print u'[%s] HTTP request failed!!! Preparing to resend....' % get_time()
            flag = True

It doesn’t have to be written as always retrying. You can also set the number of times to retrying

Similar Posts: