2013-08-23 13 views
5

sto ottenendo il seguente errore:pitone XMPP errore semplice client

AttributeError: Client instance has no attribute 'Dispatcher' 

durante l'esecuzione del seguente codice in Python 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) 

sarebbe felice se qualcuno sa come risolvere il problema.

P.S. traceback completo dell'errore dopo la correzione proposta da 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' 

Prima la correzione:

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

Si prega di includere il traceback * full * per l'errore. –

+0

@Martijn Pieters. L'ho fatto. – user1264304

+1

L'attributoError sembra essere un problema che si verifica * dopo * la connessione non è riuscita a causa di un timeout. Sei dietro un firewall? –

risposta

3

È necessario specificare un server che si desidera connettersi.

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

Dopo averlo modificato, non è stato possibile riprodurre l'Errore Attributo.

Vorrei anche consigliare di utilizzare un JID corretto per testare il codice. I JID sono come E-Mail separati da un @, motivo per cui nel codice di esempio jid.getNode() non restituisce nulla.

* Modifica il mio esempio di codice:

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

Grazie. Sto ancora ricevendo l'errore, puoi vedere il traceback completo nella mia domanda modificata. Scusa, l'ho risolto nella domanda. In realtà, ho un vero JID nel mio codice. – user1264304

+0

Ho aggiunto il mio codice di lavoro nella mia risposta. Spero che possa aiutarti. – N3RO

+0

@ N3RO. Grazie, ha funzionato a casa mia, ma non al computer collegato alla rete di dominio. – user1264304

3

Nel vostro traceback sembra che si sta tentando di connettersi a talk.gmail.com che è un dominio inesistente, per cui la dichiarazione connection.connect non riuscirà ad aprire una connessione.

Provare a connettersi a talk.google.com che potrebbe essere il nome del server corretto.