zoukankan      html  css  js  c++  java
  • 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_virtualenvautotestlibsite-packagesurllib3connection.py", line 159, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File "D:My_virtualenvautotestlibsite-packagesurllib3utilconnection.py", line 57, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "d:pythonpython37libsocket.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

  • 相关阅读:
    随笔
    梨花落(短篇小说)
    javascript中的apply,call,bind详解
    js中this的指向问题
    你若安好,便是晴天
    gulp
    图标
    normalize.css
    git bash和toritoise客户端结合使用
    云计算基础知识
  • 原文地址:https://www.cnblogs.com/kaerxifa/p/13496074.html
Copyright © 2011-2022 走看看