关于xmpp协议发送消息,登录认证SSL报错的问题
Q:错误描述如下
-
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 文件进行修复:
修改如下:( - 行标识删除 +行标识添加)
-
-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