Solve the problem of Python certificate verify failed

Source: Internet
Author: User
Tags ssl certificate

Error when opening HTTPS using Urllib2.urlopen: urllib2.urlerror: <urlopen error [ssl:certificate_verify_failed] Certificate Verify failed (_ssl.c:590) >

This error occurs because the HTTPS certificate for the target Web site was not purchased at the certificate issuing authority.

The cause of the problem is "ssl:certificate_verify_failed".

The Python upgrade to 2.7.9 introduces a new feature that validates an SSL certificate once you open an HTTPS link using Urllib.urlopen.

A urllib2 is thrown when the target site uses a self-signed certificate. Urlerror: Error message, detailed information can be viewed here (https://www.python.org/dev/peps/pep-0476/).


Solution:


1. Create an unauthenticated context using SSL and pass in the context parameter in Urlopen

Import SSL
Import Urllib2

context = Ssl._create_unverified_context ()
Print Urllib2.urlopen ("https://www.111cn.net/", Context=context). Read ()

2. Turn off certificate validation when SSL is imported

Import SSL
Import Urllib2

Ssl._create_default_https_context = Ssl._create_unverified_context
Print Urllib2.urlopen ("https://www.111cn.net/"). Read ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.