SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

后端 未结 1 363
时光说笑
时光说笑 2021-01-14 19:53

I am using python 2.7.10

request = urllib2.Request(url, data=urllib.urlencode(params))
f = urllib2.urlopen(request))

cause the following ex

相关标签:
1条回答
  • 2021-01-14 20:29

    When you access URL through browser, you browser becomes client and server becomes on which Web site is hosted. Now, since you have imported CA certificate for browser, that's why web site is opening without error in browser.

    Now, when you open same website from your python script, client becomes your python script and it is not aware of this CA certificate. Python script do not use the Windows Certificate Store, so you will have to specify a CA certificate against which the certificate verification will be done.

    So, you have tell explicitly to script regarding CA certificate which can as follow:

    urllib2.urlopen("https://dinesh.com", cafile="test_cert.pem")
    

    You can find the documentation here: urllib2.urlopen.

    UPDATE

    Snippet from the above link:

    The optional cafile and capath parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations().

    0 讨论(0)
提交回复
热议问题