我将REST API用于Cisco CMX设备,并尝试编写Python代码,该代码向该API发出GET请求。代码如下,除了更改了必要的信息外,与文件中的代码相同。from http.client import HTTPSConnectionfrom base64 import b64encode# Create HTTPS connectionc = HTTPSConnection("0.0.0.0")# encode as Base64# decode to ascii (python3 stores as byte string, need to pass as ascii value for auth)username_password = b64encode(b"admin:password").decode("ascii")headers = {'Authorization': 'Basic {0}'.format(username_password)}# connect and ask for resourcec.request('GET', '/api/config/v1/aaa/users', headers=headers)# responseres = c.getresponse()data = res.read()但是,我不断收到以下错误:Traceback (most recent call last): File "/Users/finaris/PycharmProjects/test/test/test.py", line 14, in <module> c.request('GET', '/api/config/v1/aaa/users', headers=headers) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1106, in request self._send_request(method, url, body, headers) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1151, in _send_request self.endheaders(body) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1102, in endheaders self._send_output(message_body) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 934, in _send_output self.send(msg) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 877, in send self.connect() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1260, in connect server_hostname=server_hostname) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 377, in wrap_socket我也尝试更新OpenSSL,但这没有效果。
2 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
我遇到了同样的错误,谷歌将我带到了这个问题,所以这就是我所做的,希望它可以帮助处于类似情况的其他人。
这适用于OSX。
在终端中检查我拥有哪个版本的OpenSSL:
$ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
>> OpenSSL 0.9.8zh 14 Jan 2016
由于我的OpenSSL版本太旧,无法接受答案。
因此,我不得不更新OpenSSL。要做到这一点,我更新的Python到最新版本(从3.5版到3.6版)与自制,以下一些建议的步骤在这里:
$ brew update
$ brew install openssl
$ brew install python3
然后我在使用PATH和所使用的python版本时遇到了问题,因此我刚刚创建了一个新virtualenv版本,以确保采用了最新版本的python:
$ virtualenv webapp --python=python3.6
问题已解决。
添加回答
举报
0/150
提交
取消