python - 我正在尝试使用 xmpppy 连接到 gtalk。我如何进行身份验证?我在很多地方发现的简单代码不起作用

标签 python google-talk xmpppy

我使用的代码:

import xmppy
jid = xmpp.JID('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d585e485f6d4a404c4441034e4240" rel="noreferrer noopener nofollow">[email protected]</a>')
cl = xmpp.Client(jid.getDomain())
cl.connect(server=('talk.google.com',5222))
cl.auth('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8efbfdebfccee9e3efe7e2a0ede1e3" rel="noreferrer noopener nofollow">[email protected]</a>', 'password','something')

它似乎一直工作到连接,我得到“tls”作为连接的返回。 之后,cl.auth 失败。 我尝试过使用带或不带 @gmail.com 的用户名。我尝试过使用不同的用户,所以我的密码没有错误。 我尝试使用 5223 而不是 5222,在这种情况下我得到“ssl”作为返回。

这是我得到的调试输出:

DEBUG: socket       got   <stream:stream from="gmail.com" id="960A4092BC8F9722" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
  <stream:features>
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
  <mechanism>PLAIN</mechanism>
  <mechanism>X-GOOGLE-TOKEN</mechanism>
  <mechanism>X-OAUTH2</mechanism>
  </mechanisms>
  </stream:features>
DEBUG: dispatcher   warn  Unknown stanza: features
DEBUG: dispatcher   ok    Dispatching unknown stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-sasl'] id->None
DEBUG: sasl         start Plugging <xmpp.auth.SASL instance at 0x2f22998> into <xmpp.client.Client instance at 0x2f19bd8>
DEBUG: dispatcher   info  Registering handler <bound method SASL.SASLHandler of <xmpp.auth.SASL instance at 0x2f22998>> for "challenge" type-> ns->(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   warn  Registering namespace "urn:ietf:params:xml:ns:xmpp-sasl"
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   warn  Registering protocol "challenge" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   info  Registering handler <bound method SASL.SASLHandler of <xmpp.auth.SASL instance at 0x2f22998>> for "failure" type-> ns->(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   warn  Registering protocol "failure" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   info  Registering handler <bound method SASL.SASLHandler of <xmpp.auth.SASL instance at 0x2f22998>> for "success" type-> ns->(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: dispatcher   warn  Registering protocol "success" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-sasl)
DEBUG: socket       sent  <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">Y3MxMGIwNTlAZ21haWwuY29tQGdtYWlsLmNvbQBjczEwYjA1OUBnbWFpbC5jb20AcHZ6bXZoN3FjYzE=</auth>
DEBUG: socket       error Socket error while receiving data
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/xmpppy-0.5.0rc1-py2.7.egg/xmpp/transports.py", line 153, in receive
    try: received = self._recv(BUFLEN)
SSLError: [Errno 8] _ssl.c:1359: EOF occurred in violation of protocol
DEBUG: client       stop  Disconnect detected
DEBUG: socket       error Socket operation failed
DEBUG: sasl         stop  Plugging <xmpp.auth.SASL instance at 0x2f22998> out of <xmpp.client.Client instance at 0x2f19bd8>.

最佳答案

解决了这个问题,这是最愚蠢的事情。 Gmail 阻止了访问,因为它认为我的应用程序事件“可疑且不寻常” 我必须从浏览器登录我的帐户,告诉他们是我,然后在 10 分钟内从应用程序登录

关于python - 我正在尝试使用 xmpppy 连接到 gtalk。我如何进行身份验证?我在很多地方发现的简单代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12896868/

相关文章:

python:对csv文件中的坐标进行排序

javascript - 如何在浏览器窗口最小化和服务器发出通知时播放通知提示音

python - 如何断开我的 XMPPPY 客户端对象

python - 在 Python 中一次遍历列表选择多个元素

python - 如何使用 Pandas 获取每个组中的上一个和中间日期

python - boxsizer 内的 wxpython 笔记本

python - xmpppy 连接到 gtalk 时出错

Android 注册 GTalk 传入聊天

java - 如何使用 XMPP 和 google appengine 获取 gtalk 用户的用户名?

python - XMPPPY无法连接到服务器