我收到以下错误:
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)
如果有人知道如何修理它会很高兴。
P.S。 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'
答案 0 :(得分: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()
答案 1 :(得分:3)
在您的回溯中,您似乎正在尝试连接到talk.gmail.com
这是一个不存在的域,因此connection.connect
语句将无法打开连接。
尝试连接talk.google.com
,这可能是正确的服务器名称。