Python xmpppy客户端未向App Engine XMPP客户端发送消息
大家好,
我在使用xmpppy客户端向应用引擎的xmpp客户端发送消息时遇到了一些问题。
我没有收到任何错误提示,但消息就是没有送到那里。
从应用引擎的客户端发送消息到sl4a客户端是可以的。
而且从谷歌聊天客户端发送消息到sl4a客户端也是没问题的。
如果有人能帮忙,我会非常感激。
以下是我的python代码:
import xmpp
import time
_SERVER = 'talk.google.com', 5223
commandByXMPP()
def commandByXMPP():
global xmppUsername
xmppUsername = 'garrowsbot@gmail.com'
global xmppPassword
xmppPassword = 'obscured'
global xmppClient
global operator
operator = "cellbotmote@appspot.com"
jid = xmpp.protocol.JID(xmppUsername)
xmppClient = xmpp.Client(jid.getDomain(), debug=[])
xmppClient.connect(server=_SERVER)
try:
xmppClient.RegisterHandler('message', XMPP_message_cb)
except:
exitCellbot('XMPP error. You sure the phone has an internet connection?')
if not xmppClient:
exitCellbot('XMPP Connection failed!')
return
auth = xmppClient.auth(jid.getNode(), xmppPassword, 'botty')
if not auth:
exitCellbot('XMPP Authentication failed!')
return
xmppClient.sendInitPresence()
print "XMPP username for the robot is:\n" + xmppUsername
start=time.time()
i=0
try:
outputToOperator("starting")
while time.time()-start<15:
print "tick"
xmppClient.Process(1)
i = i +1
if i % 10 == 0:
outputToOperator("hello")
outputToOperator("exiting")
except KeyboardInterrupt:
pass
def XMPP_message_cb(session, message):
jid = xmpp.protocol.JID(message.getFrom())
global operator
command = message.getBody()
print command
def outputToOperator(msg):
print "Outputting "+msg+" to " + operator
xmppClient.send(xmpp.Message(operator, msg))
1 个回答
4
1) 确认一下 garrowsbot@gmail.com 这个邮箱是否在 cellbotmote@appspot.com 的名单上。因为 GTalk 不会把陌生用户的消息送到。
2) 发送一种类型为聊天的消息:xmppClient.send(xmpp.Message(operator, msg, typ='chat'))
有些客户端对收到没有 type
属性的“普通”消息反应不太好。