gpt4 book ai didi

Python HTTPS/SSL 错误 :1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

转载 作者:太空狗 更新时间:2023-10-30 01:38:11 25 4
gpt4 key购买 nike

我正在尝试使用来自 CentOS 6.5 的 python 与 REST API 建立简单的 HTTPS 连接。安装的是 python-2.6.6-52.el6.x86_64 和 openssl-1.0.1e-16.el6_5.7.x86_64。

#!/usr/bin/env python

import httplib, json, urllib, urllib2

# Gets the session ID to host
c = httplib.HTTPSConnection("10.10.1.1")
c.request("GET", "/services/rest/V2/?method=authenticate&username=myusername&password=mypasswd&format=json")
response = c.getresponse()
data = json.loads(response.read())
session_id = data['session_id']

print "Session Created. Session ID: " + session_id

但是,它给我这个错误:

Traceback (most recent call last):
File "./test3.py", line 7, in <module>
c.request("GET", "/services/rest/V2/?method=authenticate&username=myusername&password=mypasswd&format=json")
File "/usr/lib64/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.6/httplib.py", line 951, in _send_request
self.endheaders()
File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
self._send_output()
File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
self.send(msg)
File "/usr/lib64/python2.6/httplib.py", line 739, in send
self.connect()
File "/usr/lib64/python2.6/httplib.py", line 1116, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "/usr/lib64/python2.6/ssl.py", line 342, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
File "/usr/lib64/python2.6/ssl.py", line 120, in __init__
self.do_handshake()
File "/usr/lib64/python2.6/ssl.py", line 279, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 1] _ssl.c:492: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

这是 openssl/python 兼容性问题吗?我已经找到了最新的 python 和 openssl RPM,我不想冒险通过手动编译最新的 tarball 来取消 RPM 保留。

最佳答案

如果您将服务器配置为仅接受 TLS1.2 但客户端不支持 TLS1.2,则可能会发生这种情况。至少 Ubuntu 已经修补了他们的 openssl,不在客户端提供 TLS1.1,而只在服务器端提供,以解决某些主机的一些错误。也许 RHEL/CentOS 也是。

关于Python HTTPS/SSL 错误 :1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23091945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com