pythonxmppxmpppy

python xmpp simple client error


I'm getting the following error:

AttributeError: Client instance has no attribute 'Dispatcher'

while running the following code in 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)

Would be happy if someone knows how to fix it.

P.S. Full traceback of the error after the fix proposed by 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'

Before the 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'

Solution

  • You need to specify a server you want to connect to.

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

    After changing this I couldn't reproduce the AttributeError.

    I would also advise you to use a correct JID to test your code. JID's are like E-Mails separated by an @, which is why in your sample code jid.getNode() returns nothing.

    *Edit my Code example:

    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()