HTTPSConnectionPool SSL 错误 证书验证失败

KM *_*hir 1 python error-handling python-requests

我正在研究一些特定网站的网络抓取,因此我使用 python 3 requests 包和 beautifulsoup。在对某些网站进行测试时,我收到此错误:

requests.exceptions.SSLError: HTTPSConnectionPool(host='autoglassbodyrepair.lawshield.co.uk', port=443): 超过 url 的最大重试次数: / (由 SSLError(SSLError("握手错误: Error([('SSL 例程) ', 'tls_process_server_certificate', '证书验证失败')],)",),))


import requests as rq
import bs4

current_url = 'autoglassbodyrepair.lawshield.co.uk'
try:
   req = rq.get(current_url)
except rq.exceptions.RequestException as e:
   print(e)
else:
   soup = bs4.BeautifulSoup(r.content, "html.parser")
   text = soup.findAll(text = True)

Run Code Online (Sandbox Code Playgroud)

当我尝试浏览器时,它显示证书已过期,但我可以处理 https 被禁止并变成红色的页面。我想要的是,如果出现不允许我访问该页面的异常,我会忽略它并进入下一页进行处理,但如果没有异常,我会处理当前页面并忽略那些 SSl 证书。

在此先感谢您的帮助 !

KM *_*hir 5

我明白了,它只需要忽略证书,如下面的代码所示,您会收到不安全连接的警告。

req = rq.get(current_url, verify = False)

Run Code Online (Sandbox Code Playgroud)