连接期间出现Python xmpp主机未知错误

连接期间出现Python xmpp主机未知错误,python,xmpp,Python,Xmpp,还有一些问题是相同的,但没有一个明确的答案能够真正发挥作用。我正在尝试通过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

还有一些问题是相同的,但没有一个明确的答案能够真正发挥作用。我正在尝试通过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', '')
给定的调试标志无效:始终
给定的调试标志无效:nodebuilder
调试:
调试:为/usr/lib/python2.7/dist-packages/xmpp/client.py创建调试
调试:定义的标志:始终,nodebuilder
查找_xmpp-client._tcp.server.com时出错
调试:套接字开始插入
调试:套接字启动成功连接到远程主机('server.com',5222)
调试:调度程序开始插入到
调试:调度程序信息注册命名空间“未知”
调试:调度程序信息将协议“未知”注册为xmpp.protocol.protocol(未知)
调试:调度程序信息将协议“默认”注册为xmpp.protocol.protocol(未知)
调试:dispatcher信息注册命名空间“http://etherx.jabber.org/streams"
调试:调度程序信息将协议“未知”注册为xmpp.protocol.protocol(http://etherx.jabber.org/streams)
调试:调度程序信息将协议“默认”注册为xmpp.protocol.protocol(http://etherx.jabber.org/streams)
调试:dispatcher信息注册命名空间“jabber:client”
调试:调度程序信息将协议“未知”注册为xmpp.protocol.protocol(jabber:client)
调试:调度程序信息将协议“默认”注册为xmpp.protocol.protocol(jabber:client)
调试:调度程序信息将协议“iq”注册为xmpp.protocol.iq(jabber:client)
调试:调度程序信息将协议“状态”注册为xmpp.protocol.presence(jabber:client)
调试:调度程序信息将协议“消息”注册为xmpp.protocol.message(jabber:client)
调试:调度程序信息为“错误”类型注册处理程序->ns->(http://etherx.jabber.org/streams)
调试:调度程序警告将协议“错误”注册为xmpp.protocol.protocol(http://etherx.jabber.org/streams)
调试:套接字已发送
调试:获得套接字
调试:调度程序正常http://etherx.jabber.org/streams/error 诗节
调试:dispatcher ok调度错误节,类型->props->[u'urn:ietf:params:xml:ns:xmpp streams']id->None
回溯(最近一次呼叫最后一次):
文件“chat2.py”,第10行,在
client.connect(服务器=('server.com',5222))
文件“/usr/lib/python2.7/dist-packages/xmpp/client.py”,第200行,在connect中
如果不是CommonClient.connect(self、server、proxy、secure、use_srv)或secureNone和not secure:返回self.connected
文件“/usr/lib/python2.7/dist packages/xmpp/client.py”,第184行,在connect中
如果不是self.Process(1):返回
文件“/usr/lib/python2.7/dist packages/xmpp/dispatcher.py”,第303行,在dispatch中
处理程序['func'](会话,节)
文件“/usr/lib/python2.7/dist packages/xmpp/dispatcher.py”,第215行,在streamErrorHandler中
升起exc((名称、文本))
xmpp.protocol.HostUnknown:(u'host-unknown','')
我可以看到我正在成功地连接到服务器,但在那之后就没有意义了。我怀疑client=xmpp.client('Adium')中的“client”有问题,但不确定应该做什么,或者它是否是一个问题。你觉得怎么样


我在Python2.7上使用python xmpp,不知道这是不是不兼容或其他什么。

在代码中有这样一行:

client = xmpp.Client('Adium')
应该是:

client = xmpp.Client('server.com')
这里的参数是您要连接的XMPP主机。由于“Adium”不是服务器上可识别的主机,因此根据您的日志,它将返回一个主机未知错误:

   <stream:error>
   <host-unknown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
   </stream:error>
现在只有一个
jid
变量包含您的XMPP地址(简称为“Jabber ID”,简称jid)
jid.getDomain()
返回服务器部分,
jid.getNode()
返回jid的用户部分


我还从
client.connect()
中删除了主机和端口的手动规范。如果您的服务器和DNS配置正确,则不需要这些设置。

当错误消息明确显示“主机未知”时,是什么让您认为您成功连接的?我想我在第7行注意到了它。你的答案至少会有点帮助。小心不要太多,这只是一条调试消息。我还没有给出答案,因为你的问题还不清楚。例如,您正在使用哪个xmpp库?我正在使用python xmpp。问题很清楚。我想连接,但无法连接。我可以使用独立客户端进行正常连接,以便验证端口和服务器是否已设置。不,我只需要一个脚本就可以了。系统提供调试来显示连接错误,但我无法读取调试。做得好,这非常有帮助。我现在让它工作了。客户是最初的问题。我找不到它的定义,也找不到这里应该有什么。再次感谢
import xmpp

jid = xmpp.protocol.JID('test@server.com')
passwd = 'password'
to='test2@server.com'
msg='hello :)'

client = xmpp.Client(jid.getDomain())
client.connect()
client.auth(jid.getNode(), passwd, 'botty')