gpt4 book ai didi

python - xmpppy 和 Facebook 聊天集成

转载 作者:行者123 更新时间:2023-11-28 16:53:02 27 4
gpt4 key购买 nike

我正在尝试创建一个非常简单的脚本,它使用 python 的 xmpppy 通过 facebook 聊天发送消息。

import xmppFACEBOOK_ID = "username@chat.facebook.com"PASS = "password"SERVER = "chat.facebook.com"jid=xmpp.protocol.JID(FACEBOOK_ID)C=xmpp.Client(jid.getDomain(),debug=[])if not C.connect((SERVER,5222)):    raise IOError('Can not connect to server.')if not C.auth(jid.getNode(),PASS):    raise IOError('Can not auth with server.')C.send(xmpp.protocol.Message("friend@chat.facebook.com","Hello world",))

此代码可通过 gchat 发送消息,但是当我尝试使用 facebook 时,我收到此错误:

查找_xmpp-client._tcp.chat.facebook.com时发生错误

当我从 FACEBOOK_ID 中删除 @chat.facebook.com 时,我得到的是:

File "gtalktest.py", line 11, in     if not C.connect((SERVER,5222)):  File "/home/john/xmpppy-0.3.1/xmpp/client.py", line 195, in connect    if not CommonClient.connect(self,server,proxy,secure,use_srv) or secureNone and not secure: return self.connected  File "/home/john/xmpppy-0.3.1/xmpp/client.py", line 179, in connect    if not self.Process(1): return  File "/home/john/xmpppy-0.3.1/xmpp/dispatcher.py", line 302, in dispatch    handler['func'](session,stanza)  File "/home/john/xmpppy-0.3.1/xmpp/dispatcher.py", line 214, in streamErrorHandler    raise exc((name,text))xmpp.protocol.HostUnknown: (u'host-unknown', '')

我还注意到,每当我导入 xmpp 时,我都会在运行时收到以下两条消息:

/home/john/xmpppy-0.3.1/xmpp/auth.py:24: DeprecationWarning: the sha module is deprecated; use the hashlib module instead  import sha,base64,random,dispatcher/home/john/xmpppy-0.3.1/xmpp/auth.py:26: DeprecationWarning: the md5 module is deprecated; use hashlib instead  import md5

我对解决这类问题还很陌生,如果能提供建议或指向可以帮助我继续解决这些问题的资源链接,我们将不胜感激。感谢阅读!

最佳答案

我也开始了同样的项目,并且陷入了同样的问题。我也找到了解决方案。你必须写下 facebook 的用户名(因此你必须选择一个用户名),而且也是小写的。这是最重要的部分。很可能你也像我一样不会用小型大写字母写它。

关于python - xmpppy 和 Facebook 聊天集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4732230/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com