2013-04-24 124 views
7

Screenshot of the errorpycurl HTTPS错误:无法获取本地颁发者证书

>>> import pycurl 
>>> c = pycurl.Curl() 
>>> c.setopt(c.URL, 'https://quora.com') 
>>> c.perform() 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
pycurl.error: (60, 'SSL certificate problem: unable to get local issuer certificate') 
>>> 
>>> c.setopt(c.URL, 'http://quora.com') 
>>> c.perform() 
>>> 
>>> 

为什么无法获取本地颁发者证书?我该如何解决这个问题?当我在浏览器中打开quora.com时,我看到它的身份已被验证。为什么会这样?我如何让pycurl使用我的浏览器使用的相同证书? enter image description here

+0

相关:http://stackoverflow.com/questions/8332643/pycurl-and-ssl-cert – 2013-04-24 13:17:48

回答

15

的问题是,需要pycurl向上最新证书链来验证SSL证书。

一个好的解决方案是使用certifi

它基本上建于包裹在一个Python包可使用PIP保持最新的证书链Mozilla的一个先进的最新副本。 certifi.where()为您提供证书包的位置。

为了pycurl使用它,设置CAINFO选项:

import pycurl 
import certifi 

curl = pycurl.Curl() 
curl.setopt(pycurl.CAINFO, certifi.where()) 
curl.setopt(pycurl.URL, 'https://www.quora.com') 
curl.perform() 
相关问题