I'm about to tear my hair out with this issue. I'm using the simplest code I can think of just to test xmppy and it fails again and again. I've used sendxmpp in the past, but am trying to migrate some server side scripts to, well, use python rather than piping output to sendxmpp.
Anyway: Here's the code:
import xmpp
user = "actual.user@gmail.com"
password = "actualPassword"
server = 'talk.google.com'
jid = xmpp.JID(user)
connection = xmpp.Client(server)
connection.connect()
And here's the resulting output:
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for /Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py
DEBUG: flags defined: always,nodebuilder
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x108daae60> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: socket warn An error occurred while looking up _xmpp-client._tcp.talk.google.com
DEBUG: socket start Successfully connected to remote host ('talk.google.com', 5222)
DEBUG: dispatcher start Plugging <xmpp.dispatcher.Dispatcher instance at 0x108dbd050> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: dispatcher info Registering namespace "unknown"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(unknown)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(unknown)
DEBUG: dispatcher info Registering namespace "http://etherx.jabber.org/streams"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering namespace "jabber:client"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(jabber:client)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(jabber:client)
DEBUG: dispatcher info Registering protocol "iq" as <class 'xmpp.protocol.Iq'>(jabber:client)
DEBUG: dispatcher info Registering protocol "presence" as <class 'xmpp.protocol.Presence'>(jabber:client)
DEBUG: dispatcher info Registering protocol "message" as <class 'xmpp.protocol.Message'>(jabber:client)
DEBUG: dispatcher info Registering handler <bound method Dispatcher.streamErrorHandler of <xmpp.dispatcher.Dispatcher instance at 0x108dbd050>> for "error" type-> ns->(http://etherx.jabber.org/streams)
DEBUG: dispatcher warn Registering protocol "error" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: socket sent <?xml version='1.0'?>
<stream:stream xmlns="jabber:client" to="talk.google.com" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >
DEBUG: socket got <stream:stream from="talk.google.com" id="B0E6462206621A27" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
<stream:features>
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
<required/>
</starttls>
<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<mechanism>X-GOOGLE-TOKEN</mechanism>
<mechanism>X-OAUTH2</mechanism>
</mechanisms>
</stream:features>
DEBUG: dispatcher warn Unknown stanza: features
DEBUG: dispatcher ok Dispatching unknown stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-tls', u'urn:ietf:params:xml:ns:xmpp-sasl'] id->None
DEBUG: tls start Plugging <xmpp.transports.TLS instance at 0x108dbda28> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: tls ok TLS supported by remote server. Requesting TLS start.
DEBUG: dispatcher info Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x108dbda28>> for "proceed" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher warn Registering namespace "urn:ietf:params:xml:ns:xmpp-tls"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher warn Registering protocol "proceed" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher info Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x108dbda28>> for "failure" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher warn Registering protocol "failure" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: socket sent <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
DEBUG: socket got <stream:error>
<host-unknown xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
<str:text xmlns:str="urn:ietf:params:xml:ns:xmpp-streams">Set the 'to' attribute of stream element to the domain part of the user's JID. Example: to='gmail.com'.</str:text>
</stream:error>
</stream:stream>
DEBUG: dispatcher ok Got http://etherx.jabber.org/streams/error stanza
DEBUG: dispatcher ok Dispatching error stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-streams'] id->None
Traceback (most recent call last):
File "./sendXMPP.py", line 16, in <module>
print connection.connect()
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py", line 205, in connect
while not self.TLS.starttls and self.Process(1): pass
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/dispatcher.py", line 303, in dispatch
handler['func'](session,stanza)
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/dispatcher.py", line 215, in streamErrorHandler
raise exc((name,text))
xmpp.protocol.HostUnknown: (u'host-unknown', u"Set the 'to' attribute of stream element to the domain part of the user's JID. Example: to='gmail.com'.")
What on earth am I doing wrong here?
Edit: Updated code to show changes.
New Code:
import xmpp
user = "actual.user@gmail.com"
password = "actualPassword"
server = 'talk.google.com'
jid = xmpp.JID(user)
connection = xmpp.Client(jid.getDomain())
connection.connect()
result = connection.auth(jid.getNode(), password,"TESTING")
New Error:
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for /Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py
DEBUG: flags defined: always,nodebuilder
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x1033c0e60> into <xmpp.client.Client instance at 0x1033c0d88>
DEBUG: socket warn An error occurred while looking up _xmpp-client._tcp.gmail.com
DEBUG: socket error Failed to connect to remote host ('gmail.com', 5222): Operation timed out (60)
Traceback (most recent call last):
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/transports.py", line 133, in connect
self._sock.connect((server[0], int(server[1])))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 60] Operation timed out
DEBUG: socket stop Plugging <xmpp.transports.TCPsocket instance at 0x1033c0e60> out of <xmpp.client.Client instance at 0x1033c0d88>.
Traceback (most recent call last):
File "./sendXMPP.py", line 17, in <module>
result = connection.auth(jid.getNode(), password,"LFY-client")
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py", line 214, in auth
while not self.Dispatcher.Stream._document_attrs and self.Process(1): pass
AttributeError: Client instance has no attribute 'Dispatcher'
You should not manually set a server - xmpp.Client
will try to figure it out on its own:
import xmpp
jid = xmpp.JID("actual.user@gmail.com")
connection = xmpp.Client(jid.getDomain())
connection.connect()
should work fine.