2013-08-23 21 views
5

Dostaję następujący błąd:pyton XMPP błąd prosty klient

AttributeError: Client instance has no attribute 'Dispatcher' 

przy uruchomionej następujący kod w Pythonie 2.7:

import xmpp 

user= '[email protected]' 
password="pass" 

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

Byłby szczęśliwy, jeśli ktoś wie jak to naprawić.

P.S. Pełna traceback błędu po poprawki zaproponowanej przez 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' 

Przed fix:

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

Proszę podać * pełne * informacje zwrotne o błędzie. –

+0

@Martijn Pieters. Zrobiłem. – user1264304

+1

Atrybut AttributeError wydaje się być problemem, który występuje po * połączeniu nie powiodło się z powodu przekroczenia limitu czasu. Czy w ogóle jesteś za zaporą ogniową? –

Odpowiedz

3

Musisz określić serwer, którym chcesz się połączyć.

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

Po zmianie tego nie mogłem odtworzyć AttributeError.

Zalecam również użycie poprawnego identyfikatora JID w celu przetestowania kodu. Identyfikatory JID są jak wiadomości e-mail oddzielone znakiem @, dlatego w przykładowym kodzie jid.getNode() nic nie zwraca.

* Edycja mój przykładowy kod:

import xmpp 

user = '[email protected]' 
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() 
+0

Dzięki. Nadal dostaję błąd, możesz zobaczyć pełne informacje zwrotne w moim edytowanym pytaniu. Przepraszamy, poprawiliśmy to w pytaniu. Właściwie to mam prawdziwy JID w moim kodzie. – user1264304

+0

Dodałem mój działający kod do mojej odpowiedzi. Mam nadzieję, że to może ci pomóc. – N3RO

+0

@ N3RO. Dzięki, działało w moim domu, ale nie na komputerze podłączonym do sieci domen. – user1264304

3

w twojej traceback Wygląda jak próbujesz się połączyć talk.gmail.com który jest nie istnial domenę, więc stwierdzenie connection.connect nie uda się otworzyć połączenie.

Spróbuj połączyć się z talk.google.com, która może być nazwą właściwego serwera.