Python2.6 xmpp Jabber错误

发布于 2024-08-02 06:27:39 字数 618 浏览 2 评论 0原文

我正在使用 xmpp 和 python,我想创建一个简单的客户端来与 gmail 进行通信 ID。

#!/usr/bin/python
import xmpp

login = 'Your.Login' # @gmail.com 
pwd   = 'YourPassword'

cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )
cnx.auth(login,pwd, 'botty')

cnx.send( xmpp.Message( "[email protected]" ,"Hello World form Python" ) )

当我运行最后一行时,出现异常

IOError:与服务器断开连接。

此外,当我运行其他语句时,我会在控制台中收到调试消息。

可能是什么问题以及如何解决?

I am using xmpp with python and I want create a simple client to communicate with a gmail
id.

#!/usr/bin/python
import xmpp

login = 'Your.Login' # @gmail.com 
pwd   = 'YourPassword'

cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )
cnx.auth(login,pwd, 'botty')

cnx.send( xmpp.Message( "[email protected]" ,"Hello World form Python" ) )

When I run the last line I get an exception

IOError: Disconnected from server.

Also when I run the other statements I get debug messages in the console.

What could be the issue and how can I resolve it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吻安 2024-08-09 06:27:39

这里是它在我的 PyTalk 客户端

不要忘记用户 ID 中的 @gmail.com。

我认为您应该尝试通过 5222 端口连接 talk.google.com。

还尝试为身份验证指定资源。

import xmpp
import sys

userID   = '[email protected]' 
password = 'YourPassword'
ressource = 'Script'

jid  = xmpp.protocol.JID(userID)
jabber     = xmpp.Client(jid.getDomain(), debug=[])

connection = jabber.connect(('talk.google.com',5222))
if not connection:
    sys.stderr.write('Could not connect\n')
else:
    sys.stderr.write('Connected with %s\n' % connection)

auth = jabber.auth(jid.getNode(), password, ressource)
if not auth:
    sys.stderr.write("Could not authenticate\n")
else:
    sys.stderr.write('Authenticate using %s\n' % auth)

jabber.sendInitPresence(requestRoster=1)
jabber.send(xmpp.Message( "[email protected]" ,"Hello World form Python" ))

顺便说一句,它看起来与菲利普·回答非常接近

Here is how it did on my PyTalk client.

Don't forget the @gmail.com in the userID.

I think you should try to connect talk.google.com on the 5222 port.

Also try to specify a ressource for the auth.

import xmpp
import sys

userID   = '[email protected]' 
password = 'YourPassword'
ressource = 'Script'

jid  = xmpp.protocol.JID(userID)
jabber     = xmpp.Client(jid.getDomain(), debug=[])

connection = jabber.connect(('talk.google.com',5222))
if not connection:
    sys.stderr.write('Could not connect\n')
else:
    sys.stderr.write('Connected with %s\n' % connection)

auth = jabber.auth(jid.getNode(), password, ressource)
if not auth:
    sys.stderr.write("Could not authenticate\n")
else:
    sys.stderr.write('Authenticate using %s\n' % auth)

jabber.sendInitPresence(requestRoster=1)
jabber.send(xmpp.Message( "[email protected]" ,"Hello World form Python" ))

By the way, it looks very close from Philip Answer

往日 2024-08-09 06:27:39

试试这个代码片段。为了简单起见,我没有处理错误条件。

import xmpp

login = 'Your.Login' # @gmail.com 
pwd   = 'YourPassword'

jid = xmpp.protocol.JID(login)
cl  = xmpp.Client(jid.getDomain(), debug=[])
if cl.connect(('talk.google.com',5223)):
    print "Connected"
else:
    print "Connectioned failed"

if cl.auth(jid.getNode(), pwd):
    cl.sendInitPresence()
    cl.send(xmpp.Message( "[email protected]" ,"Hello World form Python" ))
else:
    print "Authentication failed"

要关闭调试消息,请为 Client 类构造函数的第二个参数传递 debug=[]

cl  = xmpp.Client(jid.getDomain(), debug=[])

Try this code snippet. I didn't handle the error conditions for simplicity's sake.

import xmpp

login = 'Your.Login' # @gmail.com 
pwd   = 'YourPassword'

jid = xmpp.protocol.JID(login)
cl  = xmpp.Client(jid.getDomain(), debug=[])
if cl.connect(('talk.google.com',5223)):
    print "Connected"
else:
    print "Connectioned failed"

if cl.auth(jid.getNode(), pwd):
    cl.sendInitPresence()
    cl.send(xmpp.Message( "[email protected]" ,"Hello World form Python" ))
else:
    print "Authentication failed"

To switch off the debugging messages, pass debug=[] for the 2nd parameter on the Client class's constructor:

cl  = xmpp.Client(jid.getDomain(), debug=[])
云朵有点甜 2024-08-09 06:27:39

我想你必须写这个。我用 xmpppy 0.5.0rc1 在 python 2.7 中测试它并且工作得很好:P :) :

import xmpp

login = 'your [email protected]' # @gmail.com 
pwd   = 'your pass'
text='Hello worlD!'
tojid='your friend @gmail.com'



jid = xmpp.protocol.JID(login)
cl  = xmpp.Client(jid.getDomain(), debug=[])
if cl.connect(('talk.google.com',5223)):
    print "Connected"

else:
    print "Connectioned failed"

if cl.auth(jid.getNode(), pwd):
    cl.sendInitPresence()
    cl.send(xmpp.protocol.Message(tojid,text))
else:
    print "Authentication failed"

i think you must write this. i test it in python 2.7 with xmpppy 0.5.0rc1 and work IT very nice :P :) :

import xmpp

login = 'your [email protected]' # @gmail.com 
pwd   = 'your pass'
text='Hello worlD!'
tojid='your friend @gmail.com'



jid = xmpp.protocol.JID(login)
cl  = xmpp.Client(jid.getDomain(), debug=[])
if cl.connect(('talk.google.com',5223)):
    print "Connected"

else:
    print "Connectioned failed"

if cl.auth(jid.getNode(), pwd):
    cl.sendInitPresence()
    cl.send(xmpp.protocol.Message(tojid,text))
else:
    print "Authentication failed"
謸气贵蔟 2024-08-09 06:27:39

我认为您需要在发送第一条消息之前调用 sendInitPresence

...
cnx.auth(login,pwd, 'botty')
cnx.sendInitPresence()
cnx.send( xmpp.Message( "[email protected]" ,"Hello World form Python" ) )

I think you need to call sendInitPresence before sending the first message:

...
cnx.auth(login,pwd, 'botty')
cnx.sendInitPresence()
cnx.send( xmpp.Message( "[email protected]" ,"Hello World form Python" ) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文