#超时 from requests.exceptions import ConnectionError,ConnectTimeout,RequestException try: r=requests.get('http://www.baidu.com',timeout=0.1) print(r.text) except ConnectTimeout: print('timeout') except ConnectionError: print('conerror') except RequestException as e: print(e)
运行结果
HTTPConnectionPool(host='www.baidu.com', port=80): Read timed out. (read timeout=0.1)