requests.exceptions.ConnectionError: HTTPSConnectionPool(host='appts.xxx.com%20', port=443):

开了5个线程 使用requests.post访问一台服务器

 

错误提示:


Exception in thread Thread-2: Traceback (most recent call last): File "D:\My_virtualenv\autotest\lib\site-packages\urllib3\connection.py", line 159, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File "D:\My_virtualenv\autotest\lib\site-packages\urllib3\util\connection.py", line 57, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "d:\python\python37\lib\socket.py", line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

 

...
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=appts.5i5j.com%20, port=443): Max retries exceeded with url: / (Caused by NewConnectionError(<urllib3.connection.VerifiedHTTPSConnection object at 0x00000207472C8390>: Fa
iled to establish a new connection: [Errno 11001] getaddrinfo failed))

 

错误原因:

1.有可能请求过多过快

2.访问的url地址错误(我是此种情况)

 

解决办法:

加上异常处理,遇到不可访问的url,打印出来。不影响继续访问后续的url

        try:
            response = requests.get(url, verify=False, timeout=5)
        except requests.exceptions.ConnectionError:
            print("Site not rechable", url)
            

 执行脚本后输入结果如下:

[2020-08-13 14:17:24,552][ERROR] https://appapi.xxx.com  is not rechable

由此得知是url拼接错导致发送post请求时不能抵达url

修正url后,可以正常访问了

 

参考文档:

Python: requests.exceptions.ConnectionError: HTTPSConnectionPool

requests.exceptions.ConnectionError:HTTPSConnectionPool(host

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='appts.xxx.com%20', port=443):

上一篇:手机号码查询归属地


下一篇:Kotlin实战项目——天气预报类APP