【发布时间】:2012-07-05 05:49:26
【问题描述】:
谁能帮我修复这段代码,我真的需要它,但不知道下一步该做什么。我需要创建一个群聊并向受邀者发送消息,现在是 example2@gmail.com,但它没有...
有错吗?
#!/usr/bin/python
import sys,os,xmpp,time
jid = 'example1@gmail.com'
psw = 'psw'
jid=xmpp.protocol.JID(jid)
cl=xmpp.Client(jid.getDomain(),debug=[])
cl.connect()
cl.auth(jid.getNode(),psw)
node = jid.getNode()
domain = 'talk.google.com'
room = node + '@' + domain
nroom = room + '/' + 'Maria'
mes = xmpp.Presence(to=nroom)
cl.sendInitPresence()
cl.send(mes)
NS_MUCUSER = 'http://jabber.org/protocol/muc#user'
invite = xmpp.simplexml.Node('invite')
invite.setAttr('to', 'example2@gmail.com')
invite.setTagData('reason', 'I really need it!')
mess = xmpp.Message(to=room)
mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite)
cl.send(mess)
msg = xmpp.protocol.Message(body="Hello there!")
msg.setTo(room)
msg.setType('groupchat')
cl.send(msg)
time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending
cl.disconnect()
print "Done"
【问题讨论】:
-
嗨,玛丽亚,如果你展示你迄今为止所做的事情,你会得到更多更好的答案 - 一些代码的 sn-ps 展示了你在哪里感到困惑。
-
我知道这里有错误,但我能做的就是...
标签: python xmpp chat chatroom xmpppy