Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

python - 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)

I run this script but I got this error. How can I do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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:

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):

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

Fore completeness, the relevant verify parameter is described in requests.request() docs:

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...