【发布时间】:2015-04-05 21:03:29
【问题描述】:
还有其他相同的问题,但没有一个具有实际作用的明确答案。我正在尝试通过 python-xmpp 发送聊天消息:
import xmpp
username = 'test@server.com'
passwd = 'password'
to='test2@server.com'
msg='hello :)'
client = xmpp.Client('Adium')
client.connect(server=('server.com',5222))
client.auth(username, passwd, 'botty')
client.sendInitPresence()
message = xmpp.Message(to, msg)
message.setAttr('type', 'chat')
client.send(message)
但是我不明白返回的错误:
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for /usr/lib/python2.7/dist-packages/xmpp/client.py
DEBUG: flags defined: always,nodebuilder
An error occurred while looking up _xmpp-client._tcp.server.com
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0xc04940> into <xmpp.client.Client instance at 0xc04350>
DEBUG: socket start Successfully connected to remote host ('server.com', 5222)
DEBUG: dispatcher start Plugging <xmpp.dispatcher.Dispatcher instance at 0xc04af8> into <xmpp.client.Client instance at 0xc04350>
DEBUG: dispatcher info Registering namespace "unknown"
DEBUG: dispatcher info Registering protocol "unknown" as xmpp.protocol.Protocol(unknown)
DEBUG: dispatcher info Registering protocol "default" as xmpp.protocol.Protocol(unknown)
DEBUG: dispatcher info Registering namespace "http://etherx.jabber.org/streams"
DEBUG: dispatcher info Registering protocol "unknown" as xmpp.protocol.Protocol(http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering protocol "default" as xmpp.protocol.Protocol(http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering namespace "jabber:client"
DEBUG: dispatcher info Registering protocol "unknown" as xmpp.protocol.Protocol(jabber:client)
DEBUG: dispatcher info Registering protocol "default" as xmpp.protocol.Protocol(jabber:client)
DEBUG: dispatcher info Registering protocol "iq" as xmpp.protocol.Iq(jabber:client)
DEBUG: dispatcher info Registering protocol "presence" as xmpp.protocol.Presence(jabber:client)
DEBUG: dispatcher info Registering protocol "message" as xmpp.protocol.Message(jabber:client)
DEBUG: dispatcher info Registering handler <bound method Dispatcher.streamErrorHandler of <xmpp.dispatcher.Dispatcher instance at 0xc04af8>> for "error" type-> ns->(http://etherx.jabber.org/streams)
DEBUG: dispatcher warn Registering protocol "error" as xmpp.protocol.Protocol(http://etherx.jabber.org/streams)
DEBUG: socket sent <?xml version='1.0'?>
<stream:stream xmlns="jabber:client" to="Adium" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >
DEBUG: socket got <?xml version='1.0'?>
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='4001548908' from='server.com' xml:lang='en'>
<stream:error>
<host-unknown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
</stream:error>
</stream:stream>
DEBUG: dispatcher ok Got http://etherx.jabber.org/streams/error stanza
DEBUG: dispatcher ok Dispatching error stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-streams'] id->None
Traceback (most recent call last):
File "chat2.py", line 10, in <module>
client.connect(server=('server.com',5222))
File "/usr/lib/python2.7/dist-packages/xmpp/client.py", line 200, in connect
if not CommonClient.connect(self,server,proxy,secure,use_srv) or secure<>None and not secure: return self.connected
File "/usr/lib/python2.7/dist-packages/xmpp/client.py", line 184, in connect
if not self.Process(1): return
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/dispatcher.py", line 215, in streamErrorHandler
raise exc((name,text))
xmpp.protocol.HostUnknown: (u'host-unknown', '')
我可以看到我已成功连接到服务器,但之后就没有任何意义了。我怀疑 client = xmpp.Client('Adium') 中的“客户端”存在问题,但不确定应该去那里,或者它是否是一个问题。你怎么看?
我在 python 2.7 上使用 python-xmpp,想知道这是否不兼容。
【问题讨论】:
-
当错误消息清楚地显示“主机未知”时,是什么让您认为您已成功连接?
-
我以为我在第 7 行注意到了。您的回答至少会更有帮助。
-
注意不要过分强调,这只是一个调试信息。而且我还没有发布答案,因为您的问题仍然不清楚。例如,您使用的是哪个 xmpp 库?
-
我正在使用 python-xmpp。问题很清楚。我想连接,不能。我可以使用标准客户端进行正常连接,以便验证我的端口和服务器是否已设置。不,我只需要让脚本也可以工作。系统提供调试显示连接错误,但我无法读取调试。