自动化测试交流学习群,不定期会有群成员分享一些技巧和工具知识,欢迎加入...
Selenium学习成长群

关于xmpp协议发送消息,登录认证SSL报错的问题

Q:错误描述如下

  1. Traceback(most recent call last):
    File"/tails-share/features/scripts/otr-bot.py", line 197,in<module>
    otr_bot.serve_forever()
    File"/usr/lib/python2.7/dist-packages/jabberbot.py", line 715,in serve_forever
    conn = self.connect()
    File"/tails-share/features/scripts/otr-bot.py", line 82,in connect
    conres = conn.connect((conn_server, int(conn_port)))
    File"/usr/lib/python2.7/dist-packages/xmpp/client.py", line 205,in connect
    while not self.TLS.starttls and self.Process(1): pass
    File"/usr/lib/python2.7/dist-packages/xmpp/dispatcher.py", line 303,in dispatch
    handler['func'](session,stanza)
    File"/usr/lib/python2.7/dist-packages/xmpp/transports.py", line 330,inStartTLSHandler
    self._startSSL()
    File"/usr/lib/python2.7/dist-packages/xmpp/transports.py", line 309,in _startSSL
    tcpsock._sslIssuer = tcpsock._sslObj.issuer()
    AttributeError:'_ssl._SSLSocket' object has no attribute 'issuer'

该问题是xmpp新版的python中存在的一个bug。可以修改 transports.py 文件进行修复:
修改如下:( - 行标识删除 +行标识添加)

  1. -import socket,select,base64,dispatcher,sys
    +import socket,ssl,select,base64,dispatcher,sys
    from simplexml import ustr
    from client importPlugIn
    from protocol import*
    @@-312,9+312,9@@class TLS(PlugIn):
    """ Immidiatedly switch socket to TLS mode. Used internally."""
    """ Here we should switch pending_data to hint mode."""
    tcpsock=self._owner.Connection
    - tcpsock._sslObj = socket.ssl(tcpsock._sock,None,None)
    - tcpsock._sslIssuer = tcpsock._sslObj.issuer()
    - tcpsock._sslServer = tcpsock._sslObj.server()
    + tcpsock._sslObj = ssl.wrap_socket(tcpsock._sock,None,None)
    + tcpsock._sslIssuer = tcpsock._sslObj.getpeercert().get('issuer')
    + tcpsock._sslServer = tcpsock._sslObj.getpeercert().get('server')
    tcpsock._recv = tcpsock._sslObj.read
    tcpsock._send = tcpsock._sslObj.write

 

posted @ 2015-06-30 17:23  oO_Ray  阅读(1002)  评论(0编辑  收藏  举报