Python Twisted-SleekXMPP兼容性
我正在用python制作一个XMPP中间件,它监听一个地址(主机、端口),当它在该端口上接收到一些连接时,它会向服务器上的jid(XMPP用户)发送一条XMPP消息。 快速查看我的设置 对于网络部分,我使用twisted 对于XMPP-光滑的XMPP XMPP服务器-Openfire 现在,当我尝试使用sleekXMPP而不从twistedm导入任何内容时,效果很好。 然而,我尝试在一个程序中混合sleekXMPP和twisted(通过导入它们),我得到了以下错误Python Twisted-SleekXMPP兼容性,python,xmpp,twisted,Python,Xmpp,Twisted,我正在用python制作一个XMPP中间件,它监听一个地址(主机、端口),当它在该端口上接收到一些连接时,它会向服务器上的jid(XMPP用户)发送一条XMPP消息。 快速查看我的设置 对于网络部分,我使用twisted 对于XMPP-光滑的XMPP XMPP服务器-Openfire 现在,当我尝试使用sleekXMPP而不从twistedm导入任何内容时,效果很好。 然而,我尝试在一个程序中混合sleekXMPP和twisted(通过导入它们),我得到了以下错误 Traceback (most
Traceback (most recent call last):
File "sleekXMPP/prog_3.py", line 124, in <module>
main()
File "sleekXMPP/prog_3.py", line 111, in main
xmppThread = ClientThread(dir_q)
File "sleekXMPP/prog_3.py", line 41, in __init__
self.xmpp = xmppClient(self.jid, self.password)
File "sleekXMPP/prog_3.py", line 17, in __init__
sleekxmpp.ClientXMPP.__init__(self, jid, password)
File "build\bdist.win32\egg\sleekxmpp\clientxmpp.py", line 65, in __init__
File "build\bdist.win32\egg\sleekxmpp\basexmpp.py", line 72, in __init__
File "build\bdist.win32\egg\sleekxmpp\jid.py", line 461, in __init__
File "build\bdist.win32\egg\sleekxmpp\jid.py", line 150, in _parse_jid
File "build\bdist.win32\egg\sleekxmpp\jid.py", line 202, in _validate_domain
File "C:\Python27\lib\site-packages\twisted-12.2.0-py2.7-win32.egg\twisted\python \compat.py", line 22, in inet_pton
raise ValueError("Illegal characters: %r" % (''.join(x),))
ValueError: Illegal characters: u't'
注意,在这段代码中,对实际的网络代码进行了注释,我使用reqSimulator类来模拟即将到来的请求。
我试图在谷歌上搜索任何发布的内容,但没有结果。有人知道这里出了什么问题吗?这是因为Twisted实现了inet\u pton for Windows,但对故障使用了与stdlib版本不同的异常
我已经在github上修复了Sleek(master和develop分支),不久将有一个新的point版本发布。@ZagorulkinDmitry添加了代码:-)您使用的是什么版本的SleekXMPP?感谢您的解决方案。这就是问题所在。但是在resolver.py中也存在同样的问题,在我进行了更正之后,我的程序为我工作。我也在github上提交了一个与此相关的问题。
import sleekxmpp
import ssl
import Queue
import threading
import time
import logging
import traceback
import sys
from twisted.internet import reactor, protocol , endpoints
class xmppClient(sleekxmpp.ClientXMPP):
"""
This class defines the xmppClient object used to interact with the XMPP server
"""
def __init__(self, jid, password):
# the constructor
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.add_event_handler('session_start', self.start)
def start(self, event):
self.send_presence()
self.get_roster()
def send_note(self):
self.mssg = r"Hello from XMPP Service"
self.recipient = r"testuser2@ghost"
self.send_message(mto=self.recipient,
mbody=self.mssg,
mtype='chat')
print "Message sent"
class ClientThread(threading.Thread):
def __init__(self, dir_q):
super(ClientThread, self).__init__()
self.dir_q = dir_q
self.stoprequest = threading.Event()
self.jid = 'testuser1@ghost'
self.password = 'password'
self.xmpp = xmppClient(self.jid, self.password)
self.xmpp.register_plugin('xep_0030') # Service Discovery
self.xmpp.register_plugin('xep_0004') # Data Forms
self.xmpp.register_plugin('xep_0060') # PubSub
self.xmpp.register_plugin('xep_0199') # XMPP Ping
self.xmpp.ssl_version = ssl.PROTOCOL_SSLv3
if self.xmpp.connect():
print("Connected")
self.xmpp.process(block=False)
else:
print("Unable to connect.")
def run(self):
while not self.stoprequest.isSet():
try:
req = self.dir_q.get(True, 0.05)
if req == 1:
self.xmpp.send_note()
except Queue.Empty:
continue
def join(self, timeout=None):
self.stoprequest.set()
super(ClientThread, self).join(timeout)
class reqSimulator(threading.Thread):
def __init__(self, dir_q):
super(reqSimulator, self).__init__()
self.dir_q = dir_q
def run(self):
while(1):
self.dir_q.put(1)
time.sleep(0.5)
"""class sendProtocol(protocol.Protocol):
def connectionMade(self):
r = reqSimulator(self.factory.dir_q)
r.run()
def connectionLost(self, reason):
pass
def dataReceived(self, data):
self.transport.loseConnection()"""
def main():
logging.basicConfig()
dir_q = Queue.Queue()
xmppThread = ClientThread(dir_q)
xmppThread.start()
sim = reqSimulator(dir_q)
"""factory = protocol.ServerFactory()
factory.dir_q = dir_q
factory.protocol = sendProtocol
endpoints.serverFromString(reactor, "tcp:8001").listen(factory)
reactor.run()
"""
sim.start()
if __name__ == "__main__":
main()