Python httplib SSL客户端问题

问题描述 投票:1回答:0

我有以下功能:

def soap(self, xml):
    """ Transport function """
    slash = self.apiurl.find('/')
    addr = self.apiurl[:slash]
    path = self.apiurl[slash:]

    conn = httplib.HTTPSConnection(addr)
    conn.putrequest("POST", path)
    conn.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
    conn.putheader("Content-length", "%d" % len(xml))
    conn.endheaders()
    conn.send(xml) 
    rez = conn.getresponse()
    content = rez.read()
    conn.close()
    return rez, content

当我尝试使用此功能连接到服务器时,出现以下错误:

    conn.endheaders()
  File "/usr/lib/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib/python2.6/httplib.py", line 1116, in connect
    self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File "/usr/lib/python2.6/ssl.py", line 338, in wrap_socket
    suppress_ragged_eofs=suppress_ragged_eofs)
  File "/usr/lib/python2.6/ssl.py", line 120, in __init__
    self.do_handshake()
  File "/usr/lib/python2.6/ssl.py", line 279, in do_handshake
    self._sslobj.do_handshake()

Python 2.6。 奇怪的是,当我尝试每秒进行第二次连接时,它可以正常工作。 如何克服SSL问题? 我做错了什么?

python ssl client httplib
© www.soinside.com 2019 - 2024. All rights reserved.