2
votes

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?

1

1 Answers

3
votes

You're doing everything correctly in your script. It appears to be a temporary issue on Facebook's end (as hinted by Socket Error #111: Connection refused). Testing against both master and develop branches of Sleek, your script connects and logs in fine for me.

Looking at the Facebook XMPP Developer Relations group, there haven't been any outage reports recently, so I'm not sure what the service situation currently is.

As an extra note, since you're dealing with Facebook, if you want to use the X-FACEBOOK-PLATFORM authentication method, then you can set:

chatbot.credentials['api_key'] = '...API_KEY...'
chatbot.credentials['access_token'] = '...TOKEN...'

Don't forget that there is also the [email protected] room if you need Sleek related help.

-- Lance