python - 我正在尝试检索 URL,但一直遇到 SSLError: HTTPSConnectionPool(host='developer.uspto.gov', port=443)
问题描述
我正在尝试从 USPTO 设置的 API 中检索 URL。他们的系统为查询提供了一个 URL,在 Web 浏览器中搜索时它工作得很好。但是在 Python3 中这样做时我一直收到这个错误
我尝试使用 urllib 和 requests 来检索数据。
我的代码:
import requests
link = new_url
f = requests.get("https://developer.uspto.gov/ibd-api/v1/patent/application?searchText=device&start=0&rows=2000")
print(f.text)
错误:
SSLError: HTTPSConnectionPool(host='developer.uspto.gov', port=443): Max
retries exceeded with url: /ibd-api/v1/patent/application?
searchText=device&start=0&rows=2000 (Caused by SSLError(SSLError("bad
handshake: Error([('SSL routines', 'tls_process_server_certificate',
'certificate verify failed')])")))
我希望能够使用 json 库读取此 URL 的内容。
解决方案
通过添加verify = False
到您的获取请求中,可以轻松解决此错误。
我建议用这个替换你当前的代码:
import requests
link = new_url
f = requests.get("https://developer.uspto.gov/ibd-api/v1/patent/application?searchText=device&start=0&rows=2000", verify=False)
print(f.text)
这里有更多信息 SSL 证书验证。
希望这可以帮助
推荐阅读
- reactjs - 对 Shopify API 的 REST API 调用从不返回任何内容,并在超时后抛出 504
- css - 图片在类内扩展而不会失真
- android - 在ios上安装深度链接后如何测试?
- postgresql - 从另一个表更新一个列值的 PostgreSQL 语法
- ios - 为什么我的链接对象没有领域?
- excel - 使用事件触发器将值从一个范围粘贴到单元格和另一个范围,并使用 sum 函数保持运行总计 [VBA]
- swiftui - 打开通知时在 WKWebView 中加载 url
- python - pip 安装包中的虚拟环境(或替代方案)
- python - 具有请求和响应的 Flask 中间件
- c++ - 使用 boost 数据结构和 nghttp2 的 C++ 程序未编译