SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed
1 2 3 4 5 6 7 8 | from lxml import html import requests url ="https://website.com/" page = requests.get(url) tree = html.fromstring(page.content) page.content |
- > SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:748)
我运行此脚本,但我收到此错误。 我该怎么做?
由于您的URL是"内部公司URL"(如评论中所述),我猜它使用自签名证书,或者由自签名CA证书颁发。
如果确实如此,您有两种选择:
(1)通过
1 | requests.get('https://website.lo', verify='/path/to/certfile') |
或(2),完全禁用客户端证书验证(但要注意所需的所有安全风险,如简单的中间人攻击等):
1 | requests.get('https://website.lo', verify=False) |
在完整性方面,相关的
1
2
3 verify -- (optional) Either a boolean, in which case it controls whether we verify
the server's TLS certificate, or a string, in which case it must be a path
to a CA bundle to use. Defaults to True.
使用以下代码而不使用SSL
1 2 3 4 5 6 7 8 | from lxml import html import requests url ="http://website.com/" page = requests.get(url) tree = html.fromstring(page.content) page.content |