gpt4 book ai didi

python - xmpppy 连接到 gtalk 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 19:13:03 27 4
gpt4 key购买 nike

我快要为这个问题抓狂了。我正在使用我能想到的最简单的代码来测试 xmppy,但它一次又一次地失败。我过去使用过 sendxmpp,但我正在尝试将一些服务器端脚本迁移到使用 python,而不是通过管道输出到 sendxmpp。

无论如何:这是代码:

import xmpp

user = "actual.user@gmail.com"
password = "actualPassword"
server = 'talk.google.com'

jid = xmpp.JID(user)
connection = xmpp.Client(server)
connection.connect()

这是结果输出:

Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for /Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py
DEBUG: flags defined: always,nodebuilder
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x108daae60> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: socket warn An error occurred while looking up _xmpp-client._tcp.talk.google.com
DEBUG: socket start Successfully connected to remote host ('talk.google.com', 5222)
DEBUG: dispatcher start Plugging <xmpp.dispatcher.Dispatcher instance at 0x108dbd050> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: dispatcher info Registering namespace "unknown"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(unknown)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(unknown)
DEBUG: dispatcher info Registering namespace "http://etherx.jabber.org/streams"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering namespace "jabber:client"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(jabber:client)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(jabber:client)
DEBUG: dispatcher info Registering protocol "iq" as <class 'xmpp.protocol.Iq'>(jabber:client)
DEBUG: dispatcher info Registering protocol "presence" as <class 'xmpp.protocol.Presence'>(jabber:client)
DEBUG: dispatcher info Registering protocol "message" as <class 'xmpp.protocol.Message'>(jabber:client)
DEBUG: dispatcher info Registering handler <bound method Dispatcher.streamErrorHandler of <xmpp.dispatcher.Dispatcher instance at 0x108dbd050>> for "error" type-> ns->(http://etherx.jabber.org/streams)
DEBUG: dispatcher warn Registering protocol "error" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)
DEBUG: socket sent <?xml version='1.0'?>
<stream:stream xmlns="jabber:client" to="talk.google.com" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >
DEBUG: socket got <stream:stream from="talk.google.com" id="B0E6462206621A27" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
<stream:features>
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
<required/>
</starttls>
<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<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-tls', u'urn:ietf:params:xml:ns:xmpp-sasl'] id->None
DEBUG: tls start Plugging <xmpp.transports.TLS instance at 0x108dbda28> into <xmpp.client.Client instance at 0x108daad88>
DEBUG: tls ok TLS supported by remote server. Requesting TLS start.
DEBUG: dispatcher info Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x108dbda28>> for "proceed" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher warn Registering namespace "urn:ietf:params:xml:ns:xmpp-tls"
DEBUG: dispatcher info Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher info Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher warn Registering protocol "proceed" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher info Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x108dbda28>> for "failure" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: dispatcher warn Registering protocol "failure" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)
DEBUG: socket sent <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
DEBUG: socket got <stream:error>
<host-unknown xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
<str:text xmlns:str="urn:ietf:params:xml:ns:xmpp-streams">Set the 'to' attribute of stream element to the domain part of the user's JID. Example: to='gmail.com'.</str:text>
</stream:error>
</stream:stream>
DEBUG: dispatcher ok Got http://etherx.jabber.org/streams/error stanza
DEBUG: dispatcher ok Dispatching error stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-streams'] id->None
Traceback (most recent call last):
File "./sendXMPP.py", line 16, in <module>
print connection.connect()
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py", line 205, in connect
while not self.TLS.starttls and self.Process(1): pass
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/dispatcher.py", line 303, in dispatch
handler['func'](session,stanza)
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/dispatcher.py", line 215, in streamErrorHandler
raise exc((name,text))
xmpp.protocol.HostUnknown: (u'host-unknown', u"Set the 'to' attribute of stream element to the domain part of the user's JID. Example: to='gmail.com'.")

我到底做错了什么?

编辑:更新代码以显示更改。

新代码:

import xmpp

user = "actual.user@gmail.com"
password = "actualPassword"
server = 'talk.google.com'

jid = xmpp.JID(user)
connection = xmpp.Client(jid.getDomain())
connection.connect()
result = connection.auth(jid.getNode(), password,"TESTING")

新错误:

Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for /Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py
DEBUG: flags defined: always,nodebuilder
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x1033c0e60> into <xmpp.client.Client instance at 0x1033c0d88>
DEBUG: socket warn An error occurred while looking up _xmpp-client._tcp.gmail.com
DEBUG: socket error Failed to connect to remote host ('gmail.com', 5222): Operation timed out (60)
Traceback (most recent call last):
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/transports.py", line 133, in connect
self._sock.connect((server[0], int(server[1])))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 60] Operation timed out
DEBUG: socket stop Plugging <xmpp.transports.TCPsocket instance at 0x1033c0e60> out of <xmpp.client.Client instance at 0x1033c0d88>.

Traceback (most recent call last):
File "./sendXMPP.py", line 17, in <module>
result = connection.auth(jid.getNode(), password,"LFY-client")
File "/Users/ben/Desktop/PythonScripts/XMPP/xmpp/client.py", line 214, in auth
while not self.Dispatcher.Stream._document_attrs and self.Process(1): pass
AttributeError: Client instance has no attribute 'Dispatcher'

最佳答案

您不应该手动设置服务器 - xmpp.Client 将尝试自行解决:

import xmpp

jid = xmpp.JID("actual.user@gmail.com")
connection = xmpp.Client(jid.getDomain())
connection.connect()

应该可以正常工作。

关于python - xmpppy 连接到 gtalk 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12242349/

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