6

我收到以下错误:

AttributeError: Client instance has no attribute 'Dispatcher'

在 python 2.7 中运行以下代码时:

import xmpp 

user= 'uname@gmail.com'
password="pass"

jid = xmpp.JID(user) 
connection = xmpp.Client(jid.getDomain()) 
connection.connect() 
connection.auth(jid.getNode(),password)

如果有人知道如何解决它会很高兴。

PS N3RO 提出的修复后错误的完整回溯:

C:\Users\krasnovi\Desktop\temp\xmpp tests>python xmpp.client.py
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for build\bdist.win-amd64\egg\xmpp\client.py
DEBUG:  flags defined: always,nodebuilder
DEBUG: socket       start Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027C1708> into <xmpp.client.Client instance at 0x00000000027C1588>
DEBUG: socket       warn  An error occurred while looking up _xmpp-client._tcp.t
alk.gmail.com
DEBUG: socket       error Failed to connect to remote host ('talk.gmail.com', 52
23): getaddrinfo failed (11004)
Traceback (most recent call last):
  File "build\bdist.win-amd64\egg\xmpp\transports.py", line 133, in connect
    self._sock.connect((server[0], int(server[1])))
  File "C:\Python27\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
gaierror: [Errno 11004] getaddrinfo failed
DEBUG: socket       stop  Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027C1708> out of <xmpp.client.Client instance at 0x00000000027C1588>.
Traceback (most recent call last):
  File "xmpp.client.py", line 11, in <module>
    connection.auth(jid.getNode(),password)
  File "build\bdist.win-amd64\egg\xmpp\client.py", line 214, in auth
AttributeError: Client instance has no attribute 'Dispatcher'

修复前:

Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for build\bdist.win-amd64\egg\xmpp\client.py
DEBUG:  flags defined: always,nodebuilder
DEBUG: socket       start Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027ED708> into <xmpp.client.Client instance at 0x00000000027ED588>
DEBUG: socket       error Failed to connect to remote host ('xmpp.l.google.com.'
, 5222): A connection attempt failed because the connected party did not properl
y respond after a period of time, or established connection failed because conne
cted host has failed to respond (10060)
Traceback (most recent call last):
  File "build\bdist.win-amd64\egg\xmpp\transports.py", line 133, in connect
    self._sock.connect((server[0], int(server[1])))
  File "C:\Python27\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10060] A connection attempt failed because the connected party did
 not properly respond after a period of time, or established connection failed b
ecause connected host has failed to respond
DEBUG: socket       stop  Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027ED708> out of <xmpp.client.Client instance at 0x00000000027ED588>.
Traceback (most recent call last):
  File "xmpp.client.py", line 11, in <module>
    connection.auth(jid.getNode(),password)
  File "build\bdist.win-amd64\egg\xmpp\client.py", line 214, in auth
AttributeError: Client instance has no attribute 'Dispatcher'
4

2 回答 2

3

您需要指定要连接的服务器。

connection.connect(server=('serveradress.com', portnumber))

更改此设置后,我无法重现 AttributeError。

我还建议您使用正确的 JID 来测试您的代码。JID 就像由@ 分隔的电子邮件,这就是为什么在您的示例代码中 jid.getNode() 不返回任何内容。

*编辑我的代码示例:

import xmpp

user = 'username@gmail.com'
password = 'password'

jid = xmpp.JID(user)

connection = xmpp.Client(jid.getDomain())
connection.connect(server=('talk.google.com', 5223))
connection.auth(jid.getNode(), password)
connection.sendInitPresence()
于 2013-08-28T10:27:41.170 回答
3

在您的回溯中,您似乎正在尝试连接到talk.gmail.com不存在的域,因此该connection.connect语句将无法打开连接。

尝试连接到talk.google.com哪个可能是正确的服务器名称。

于 2013-08-30T13:57:14.207 回答