I'm using this sample code to connect to Facebook Chat over XMPP:
#!/usr/bin/python
import sleekxmpp
import logging
logging.basicConfig(level=logging.DEBUG)
def session_start(event):
chatbot.send_presence()
print('Session started')
chatbot.get_roster()
def message(msg):
if msg['type'] in ('chat','normal'):
print('msg received')
print(msg['body'])
msg.reply('Thanks').send()
jid = '[email protected]'
password = 'mypassword'
server = ('chat.facebook.com', 5222)
chatbot = sleekxmpp.ClientXMPP(jid,password)
chatbot.add_event_handler('session_start', session_start)
chatbot.add_event_handler('message', message)
chatbot.auto_reconnect = True
chatbot.connect(server)
chatbot.process(block=True)
Everything seems to be Ok, but when I run that code, I can't connect to Facebook server:
DEBUG:sleekxmpp.basexmpp:setting jid to [email protected]
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-6120) STARTTLS Stream Feature
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-6120) Resource Binding Stream Feature
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-3920) Start Session Stream Feature
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-6120) SASL Stream Feature
DEBUG:sleekxmpp.xmlstream.xmlstream:Trying to connect to chat.facebook.com:5222
DEBUG:sleekxmpp.xmlstream.xmlstream:Connecting to chat.facebook.com:5222
ERROR:sleekxmpp.xmlstream.xmlstream:Could not connect to chat.facebook.com:5222. Socket Error #111: Connection refused
DEBUG:sleekxmpp.xmlstream.xmlstream:Trying to connect to chat.facebook.com:5222
DEBUG:sleekxmpp.xmlstream.xmlstream:Waiting 1.97953654103 seconds before connecting.
...
Am I missing something here?