Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python requests.get():如果出现Internet连接错误,如何打印消息?_Python_Python Requests_Try Except - Fatal编程技术网

Python requests.get():如果出现Internet连接错误,如何打印消息?

Python requests.get():如果出现Internet连接错误,如何打印消息?,python,python-requests,try-except,Python,Python Requests,Try Except,我正在尝试打印错误消息:Oops!休斯顿,我们有麻烦了如果由于某种原因,在尝试使用requests.get()时出现任何internet连接问题 我已经写了下面的代码,但它总是打印Oops!休斯顿,我们有麻烦了即使尝试发送请求时没有问题 try: page = requests.get(URL, headers=headers) print("SUCCESS!") except (requests.exceptions.Timeout, requests.exceptions.

我正在尝试打印错误消息:
Oops!休斯顿,我们有麻烦了
如果由于某种原因,在尝试使用
requests.get()
时出现任何internet连接问题

我已经写了下面的代码,但它总是打印
Oops!休斯顿,我们有麻烦了即使尝试发送请求时没有问题

try:
    page = requests.get(URL, headers=headers)
    print("SUCCESS!")

except (requests.exceptions.Timeout, requests.exceptions.TooManyRedirects, requests.exceptions.RequestException, requests.exceptions.ConnectionError, requests.exceptions.HTTPError,):
    print("Oops! Houston, we have a problem!")

如果您能给我一些反馈,我将不胜感激 我相信
requests.exceptions.RequestException
正在捕获所有响应,因为当我从
except