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