简体   繁体   English

SSL:CERTIFICATE_VERIFY_FAILED 证书验证失败

[英]SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed

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] certificate verify failed (_ssl.c:748) -> SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:748)

I run this script but I got this error.我运行此脚本,但出现此错误。 How can I do it?我该怎么做?

Since your URL is "an internal corporate URL" (as stated in comments), I'm guessing it uses a self-signed certificate, or is issued by a self-signed CA certificate.由于您的 URL 是“内部公司 URL”(如评论中所述),我猜它使用自签名证书,或者由自签名 CA 证书颁发。

If that is in fact the case, you have two options:如果确实如此,您有两种选择:

(1) provide the path to your corporate CA (including the complete chain of intermediate certificates, if any) to requests.get() call via verify argument: (1) 通过verify参数提供到requests.get()调用的公司 CA(包括完整的中间证书链,如果有)的路径:

requests.get('https://website.lo', verify='/path/to/certfile')

or (2) , disable client-side certificate verification altogether (but beware of all the security risks this entails, like a simple man-in-the-middle attacks, etc):(2) ,完全禁用客户端证书验证(但要注意这带来的所有安全风险,例如简单的中间人攻击等):

requests.get('https://website.lo', verify=False)

Fore completeness, the relevant verify parameter is described inrequests.request() docs:为了完整起见,requests.request()文档中描述了相关的verify参数:

 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.

Use below code without SSL 在不使用SSL的情况下使用以下代码

from lxml import html
import requests


url = "http://website.com/"
page = requests.get(url)
tree = html.fromstring(page.content)
page.content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM