我正在使用此示例代码通过 XMPP 连接到 Facebook Chat:
#!/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 = 'myusername@chat.facebook.com'
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)
一切似乎都很好,但是当我运行该代码时,我无法连接到 Facebook 服务器:
DEBUG:sleekxmpp.basexmpp:setting jid to myusername@chat.facebook.com
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.
...
我在这里错过了什么吗?