我正在嘗試使用python連接到廚師api。我使用pychef從python連接到廚師。pychef中的ssl證書驗證
以下是代碼:
import chef
with chef.ChefAPI('https://chef-e.xxxx.com:443/organizations/xxxx', '/root/.chef/rajgourav.pem', 'rajgourav'):
n = chef.Node('chef-e.xxxx.com')
我得到以下證書錯誤:
[[email protected] py]# /appl/python27/bin/python mychef.py
Traceback (most recent call last):
File "mychef.py", line 6, in <module>
n = chef.Node('chef-e.xxxx.com')
File "/appl/python27/lib/python2.7/site-packages/chef/base.py", line 58, in __init__
data = self.api[self.url]
File "/appl/python27/lib/python2.7/site-packages/chef/api.py", line 229, in __getitem__
return self.api_request('GET', path)
File "/appl/python27/lib/python2.7/site-packages/chef/api.py", line 225, in api_request
response = self.request(method, path, headers, data)
File "/appl/python27/lib/python2.7/site-packages/chef/api.py", line 208, in request
response = self._request(method, self.url+path, data, dict((k.capitalize(), v) for k, v in request_headers.iteritems()))
File "/appl/python27/lib/python2.7/site-packages/chef/api.py", line 195, in _request
return urllib2.urlopen(request).read()
File "/appl/python27/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/appl/python27/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/appl/python27/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/appl/python27/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/appl/python27/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/appl/python27/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
能否請你幫我解決SSL證書錯誤。我知道我必須接受證書並將其添加到可信證書列表中,但不知道如何在python中執行此操作。
P.S.我能夠在沒有任何問題的情況下使用刀。
我嘗試使用ssl_verify PARAM但我得到錯誤:從api.py
TypeError: __init__() got an unexpected keyword argument 'ssl_verify'
:
def __init__(self, url, key, client, version='0.10.8', headers={}):
我的ENV一些信息:
[[email protected] py]# /appl/python27/bin/python
Python 2.7.10 (default, Aug 8 2015, 06:25:19)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import chef
>>> chef.__version__
(0, 2, 3, 'dev')
>>>
謝謝, Rajgourav Jain
我也更新了我的答案,以反映您的修改。 – StephenKing