我正在使用此示例代码通过XMPP连接到Facebook聊天:
#!/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.
...
我在这里错过了什么吗?
答案 0 :(得分:3)
你在脚本中正确地做了一切。这似乎是Facebook最终的一个临时问题(由Socket Error #111: Connection refused
暗示)。对Sleek的主分支和开发分支进行测试,您的脚本连接并为我登录。
查看Facebook XMPP开发人员关系小组,最近没有任何中断报告,所以我不确定目前的服务情况。
另外请注意,由于您正在处理Facebook,如果您想使用X-FACEBOOK-PLATFORM
身份验证方法,那么您可以设置:
chatbot.credentials['api_key'] = '...API_KEY...'
chatbot.credentials['access_token'] = '...TOKEN...'
如果您需要Sleek相关帮助,请不要忘记还有sleek@conference.jabber.org会议室。
- Lance