我有一台带有 OpenNao 发行版(基于 GENTOO)的 LINUX 机器。这台机器有 Python 2.7.3。我没有root权限。您可以从以下链接下载 Virtualbox (OpenNAO OS VirtualBox 2.1.2) 中的可执行映像(您可能需要创建一个帐户):
我的问题是我正在尝试使用以下代码向具有 TLS 1.2 的 AZURE 服务器发出呼叫请求:
import requests
url = "www.example-url.com" # it is not a real url
querystring = {"key":"value",}
headers = {'token': "4bfd740f482d48a3a894445eb6a85a83",'Username': "user",'Password':"password"}
#response = requests.request("GET", url, headers=headers, params=querystring)
response = requests.get(url, headers=headers, params=querystring, timeout=30)
我收到以下错误:
/var/persistent/home/nao/.local/lib/python2.7/site-packages/urllib3/util/ssl_.py:339: 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. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
SNIMissingWarning
/var/persistent/home/nao/.local/lib/python2.7/site-packages/urllib3/util/ssl_.py:137: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning
Traceback (most recent call last):
File "heathrowFI-3.py", line 33, in <module>
response = requests.get(url, headers=headers, params=querystring, timeout=30)
File "/var/persistent/home/nao/.local/lib/python2.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/var/persistent/home/nao/.local/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/var/persistent/home/nao/.local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/var/persistent/home/nao/.local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/var/persistent/home/nao/.local/lib/python2.7/site-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))
我尝试使用 TLS 1.2 在其他机器(Windows、Ubuntu)上发出请求,结果正常。要获取每台机器的 TLS 版本,我使用了以下命令
python -c "import json, urllib2; print json.load (urllib2.urlopen ('https://www.howsmyssl.com/a/check')) ['tls_version']"
装有 python 2.7 和 TLS 1.2 的 WINDOWS 机器:请求的结果是好的。
带有 python 2.7 和 TLS 1.2 的 UBUNTU 机器:请求的结果是好的。
我认为该错误是由 NaoQi 使用的 SSL 的 TLS 1.0 版本引起的。我向其发出请求的服务器是 Azure,并且仅支持 TLS 1.2。我在浏览器中检查了它的 TLS:
我无法更新 Python(我没有 root 权限)。
请问,你知道我怎样才能使请求对服务器起作用吗?我应该在 NAOQI 机器上将 TLS 1.0 更新为 TLS 1.2 吗?你知道如何更新它吗?
欢迎任何帮助或建议。
预先感谢,问候。