2013-04-24 263 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() 
相關問題