python请求中的requests.exceptions.ConnectionError是什么?

时间:2017-12-02 20:21:14

标签: python-3.x python-requests socket-timeout-exception connectionexception

以下错误是什么意思?

socket.timeout: The read operation timed out 
During handling of the above exception, another exception occurred:
requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='', port=443): Read
timed out. 
During handling of the above exception, another exception occurred:
requests.exceptions.ConnectionError:
HTTPSConnectionPool(host='', port=443): Read timed out.

这是我的代码:

def get(url):
    while True:
        try:
            response = session.get(url, timeout=.5).text
            break
        except requests.exceptions.ReadTimeout:
            new_session()
    return response

r = get(url)

其中session是我已完成的会话,new_session()关闭该会话,并通过requests.session()将会话设置为新会话

0 个答案:

没有答案