2016-03-15 85 views
1

我在python 2.7.5中使用pyVmomi時遇到了問題。嘗試從SDK運行示例腳本時出現SSL證書錯誤。我嘗試了所有在this帖子中提到的解決方案,但沒有人爲我工作。在python中禁止'SSL例程:SSL3_GET_SERVER_CERTIFICATE:證書驗證失敗'錯誤

下面是完整的控制檯輸出。

/usr/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning. SNIMissingWarning /usr/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning 

Traceback (most recent call last): 
    File "hello_world_vcenter.py", line 105, in <module> 
    main() 
    File "hello_world_vcenter.py", line 80, in main 
    port=int(args.port)) 
    File "/usr/lib/python2.7/site-packages/pyVim/connect.py", line 663, in SmartConnect 
    sslContext) 
    File "/usr/lib/python2.7/site-packages/pyVim/connect.py", line 552, in __FindSupportedVersion 
    sslContext) 
    File "/usr/lib/python2.7/site-packages/pyVim/connect.py", line 472, in __GetServiceVersionDescription 
    tree = __GetElementTreeFromUrl(url, sslContext) 
    File "/usr/lib/python2.7/site-packages/pyVim/connect.py", line 440, in __GetElementTreeFromUrl 
    sock = requests.get(url) 
    File "/usr/lib/python2.7/site-packages/requests/api.py", line 67, in get 
    return request('get', url, params=params, **kwargs) 
    File "/usr/lib/python2.7/site-packages/requests/api.py", line 53, in request 
    return session.request(method=method, url=url, **kwargs) 
    File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 468, in request 
    resp = self.send(prep, **send_kwargs) 
    File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send 
    r = adapter.send(request, **kwargs) 
    File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 447, in send 
    raise SSLError(e, request=request) 
requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 
+0

嘗試使用python 2.7.9或2.7.10。 – May

回答

0

看起來您正在使用自簽名證書。當通過SmartConnect連接時,請使用您自己的sslContext並禁用證書驗證。

from pyVim.connect import SmartConnect 
import ssl 

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 
context.verify_mode = ssl.CERT_NONE 

si = SmartConnect(host=somehost.com, port=443, user=someone, pwd=secret, sslContext=context) 

...或使用簽名的SSL證書。

這裏有幾個類似的問題(例如here)。

相關問題