Python xmpppy连接到gtalk时出错

Python xmpppy连接到gtalk时出错,python,google-talk,xmpppy,Python,Google Talk,Xmpppy,我要为这件事大发雷霆了。我正在使用我能想到的最简单的代码来测试xmppy,但它一次又一次地失败。我过去使用过sendxmpp,但我正在尝试将一些服务器端脚本迁移到python,而不是将输出管道化到sendxmpp 无论如何:代码如下: import xmpp user = "actual.user@gmail.com" password = "actualPassword" server = 'talk.google.com' jid = xmpp.JID(user) connection

我要为这件事大发雷霆了。我正在使用我能想到的最简单的代码来测试xmppy,但它一次又一次地失败。我过去使用过sendxmpp,但我正在尝试将一些服务器端脚本迁移到python,而不是将输出管道化到sendxmpp

无论如何:代码如下:

import xmpp

user = "actual.user@gmail.com"
password = "actualPassword"
server = 'talk.google.com'

jid = xmpp.JID(user)
connection = xmpp.Client(server)
connection.connect()
下面是结果输出:

Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG: 
DEBUG: Debug created for /Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py
DEBUG:  flags defined: always,nodebuilder
DEBUG: socket       start Plugging <xmpp.transports.TCPsocket instance at 0x108daae60> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: socket       warn  An error occurred while looking up _xmpp-client._tcp.talk.google.com
DEBUG: socket       start Successfully connected to remote host ('talk.google.com', 5222)
DEBUG: dispatcher   start Plugging <xmpp.dispatcher.Dispatcher instance at 0x108dbd050> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: dispatcher   info  Registering namespace "unknown"
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(unknown)
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(unknown)
DEBUG: dispatcher   info  Registering namespace "http://etherx.jabber.org/streams"
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: dispatcher   info  Registering namespace "jabber:client"
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(jabber:client)
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(jabber:client)
DEBUG: dispatcher   info  Registering protocol "iq" as <class 'xmpp.protocol.Iq'>(jabber:client)
DEBUG: dispatcher   info  Registering protocol "presence" as <class 'xmpp.protocol.Presence'>(jabber:client)
DEBUG: dispatcher   info  Registering protocol "message" as <class 'xmpp.protocol.Message'>(jabber:client)
DEBUG: dispatcher   info  Registering handler <bound method Dispatcher.streamErrorHandler of <xmpp.dispatcher.Dispatcher instance at 0x108dbd050>> for "error" type-> ns->(http://etherx.jabber.org/streams)
DEBUG: dispatcher   warn  Registering protocol "error" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: socket       sent  <?xml version='1.0'?>
  <stream:stream xmlns="jabber:client" to="talk.google.com" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >
DEBUG: socket       got   <stream:stream from="talk.google.com" id="B0E6462206621A27" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
  <stream:features>
  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  <required/>
  </starttls>
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
  <mechanism>X-GOOGLE-TOKEN</mechanism>
  <mechanism>X-OAUTH2</mechanism>
  </mechanisms>
  </stream:features>
DEBUG: dispatcher   warn  Unknown stanza: features
DEBUG: dispatcher   ok    Dispatching unknown stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-tls', u'urn:ietf:params:xml:ns:xmpp-sasl'] id->None
DEBUG: tls          start Plugging <xmpp.transports.TLS instance at 0x108dbda28> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: tls          ok    TLS supported by remote server. Requesting TLS start.
DEBUG: dispatcher   info  Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x108dbda28>> for "proceed" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher   warn  Registering namespace "urn:ietf:params:xml:ns:xmpp-tls"
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher   warn  Registering protocol "proceed" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher   info  Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x108dbda28>> for "failure" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher   warn  Registering protocol "failure" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: socket       sent  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
DEBUG: socket       got   <stream:error>
  <host-unknown xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
  <str:text xmlns:str="urn:ietf:params:xml:ns:xmpp-streams">Set the 'to' attribute of stream element to the domain part of the user's JID. Example: to='gmail.com'.</str:text>
  </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 "./sendXMPP.py", line 16, in <module>
    print connection.connect()
  File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py", line 205, in connect
    while not self.TLS.starttls and self.Process(1): pass
  File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/dispatcher.py", line 303, in dispatch
    handler['func'](session,stanza)
  File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/dispatcher.py", line 215, in streamErrorHandler
    raise exc((name,text))
xmpp.protocol.HostUnknown: (u'host-unknown', u"Set the 'to' attribute of stream element to the domain part of the user's JID. Example: to='gmail.com'.")
新错误:

Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG: 
DEBUG: Debug created for /Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py
DEBUG:  flags defined: always,nodebuilder
DEBUG: socket       start Plugging <xmpp.transports.TCPsocket instance at 0x1033c0e60> into <xmpp.client.Client instance at 0x1033c0d88>
DEBUG: socket       warn  An error occurred while looking up _xmpp-client._tcp.gmail.com
DEBUG: socket       error Failed to connect to remote host ('gmail.com', 5222): Operation timed out (60)
Traceback (most recent call last):
  File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/transports.py", line 133, in connect
    self._sock.connect((server[0], int(server[1])))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 60] Operation timed out
DEBUG: socket       stop  Plugging <xmpp.transports.TCPsocket instance at 0x1033c0e60> out of <xmpp.client.Client instance at 0x1033c0d88>.

Traceback (most recent call last):
  File "./sendXMPP.py", line 17, in <module>
    result = connection.auth(jid.getNode(), password,"LFY-client")
  File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py", line 214, in auth
    while not self.Dispatcher.Stream._document_attrs and self.Process(1): pass
AttributeError: Client instance has no attribute 'Dispatcher'
给定的调试标志无效:始终
给定的调试标志无效:nodebuilder
调试:
调试:为/Users/ben/Desktop/PythonScripts/XMPP/XMPP/client.py创建调试
调试:定义的标志:始终,nodebuilder
调试:套接字开始插入
调试:套接字警告查找_xmpp-client时出错。_tcp.gmail.com
调试:套接字错误无法连接到远程主机('gmail.com',5222):操作超时(60)
回溯(最近一次呼叫最后一次):
文件“/Users/ben/Desktop/PythonScripts/XMPP/XMPP/transports.py”,第133行,在connect中
self._sock.connect((服务器[0],int(服务器[1]))
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第224行,meth格式
返回getattr(self.\u sock,name)(*args)
错误:[Errno 60]操作超时
调试:套接字停止从中插入。
回溯(最近一次呼叫最后一次):
文件“/sendXMPP.py”,第17行,在
结果=connection.auth(jid.getNode(),密码,“LFY客户端”)
文件“/Users/ben/Desktop/PythonScripts/XMPP/XMPP/client.py”,第214行,在auth中
而不是self.Dispatcher.Stream.\u document\u attrs和self.Process(1):通过
AttributeError:客户端实例没有属性“Dispatcher”

您不应手动设置服务器-
xmpp。客户端将尝试自行解决此问题:

import xmpp

jid = xmpp.JID("actual.user@gmail.com")
connection = xmpp.Client(jid.getDomain())
connection.connect()

应该可以正常工作。

您不应该手动设置服务器-
xmpp。客户端将尝试自行解决:

import xmpp

jid = xmpp.JID("actual.user@gmail.com")
connection = xmpp.Client(jid.getDomain())
connection.connect()

应该很好。

这也是我最初的想法,但我甚至无法在使用该方法时达到我所能达到的程度。我已经更新了我的原始问题,以显示当我使用相同代码时会发生什么。我也接受了这个答案,因为如果没有我的环境问题,没有这个更正,应用程序仍然无法工作。谢谢:-)这也是我最初的想法,但是当我使用这种方法时,我甚至不能达到我所能达到的程度。我已经更新了我的原始问题,以显示当我使用相同代码时会发生什么。我也接受了这个答案,因为如果没有我的环境问题,没有这个更正,应用程序仍然无法工作。谢谢:-)服务器输入错误,对不起。更改了代码。嗯,更新的回溯根本不适合更新的代码-错误在第17行,但代码只包含7行。你能把这封信寄出去吗?还要确保您的DNS服务器配置正确-对于
\u xmpp-client.\u tcp.gmail.com
,应该有相当多的SRV记录。如果有疑问,请将其设置为。我更新的代码现在应该可以编译了。缺少的唯一一行是connection.auth()行,该行现在已添加。我已检查以确保(使用nslookup)我有该地址的DNS条目。谢谢你花时间帮忙。嗯,我无法重现第一条错误消息。你能提供一个到数据包转储的链接吗(例如使用)?我的整个操作系统今天早上拒绝启动(OSX),所以我已经在bootcamp下设置了我的开发环境,它可以在Windows下正常工作。将来我会确保检查多个环境。对不起,服务器输入错误。更改了代码。嗯,更新的回溯根本不适合更新的代码-错误在第17行,但代码只包含7行。你能把这封信寄出去吗?还要确保您的DNS服务器配置正确-对于
\u xmpp-client.\u tcp.gmail.com
,应该有相当多的SRV记录。如果有疑问,请将其设置为。我更新的代码现在应该可以编译了。缺少的唯一一行是connection.auth()行,该行现在已添加。我已检查以确保(使用nslookup)我有该地址的DNS条目。谢谢你花时间帮忙。嗯,我无法重现第一条错误消息。你能提供一个到数据包转储的链接吗(例如使用)?我的整个操作系统今天早上拒绝启动(OSX),所以我已经在bootcamp下设置了我的开发环境,它可以在Windows下正常工作。将来,我将确保检查多个环境。