python-3.x - 为请求 ConnectionError 捕获 Python 异常的正确方法
问题描述
我正在尝试验证一些传递给我的 url。我想确保他们解析到现有网站。在此过程中,我编写了代码:
try:
logoStatus = requests.request('GET', logo)
feedStatus = requests.request('GET', feed)
except requests.exceptions.ConnectionError:
代码不会在异常处理程序处停止,而是停止并显示以下内容:
发生异常: ConnectionError HTTPConnectionPool(host='some.web.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f33d102f978>: 无法建立新连接:[Errno -2] Name or service not known',))
我提到了使用 Python requests 模块尝试/排除的正确方法?在尝试对此进行编码时,但是,它似乎对我不起作用。
有人可以指出我做错了什么吗?
解决方案
推荐阅读
- ansible - 创建收集托管主机信息并将它们写入每个主机上的文件的剧本
- python - 如何使用 openpyxl 将图像保存到 excel 文件中?
- google-chrome - 在没有活动选项卡权限的情况下使用 chrome 选项卡捕获/在没有用户输入的情况下获取活动选项卡权限
- python - 使用 Python 从 Google Drive 下载文件
- python - 勒让德多项式 Python
- python - 如何检查字符串是否包含Python列表中的特定字符?
- java - 如何在 Cucumber 特征文件中传递具有不同数量参数的多个示例
- node.js - CORB 阻止跨域响应(错误的 MIME 类型)
- typescript - 如何在 Ionic React 中将道具传递给选项卡
- c++ - 在编译时检测 std::tuple 中的类型包含