首页 > 解决方案 > 我正在尝试检索 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 的内容。

标签: pythonpython-3.xpython-requestsurllib

解决方案


通过添加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 证书验证。

希望这可以帮助


推荐阅读