Python xmpppy客户端不向appengine xmpp客户端发送消息

时间:2011-01-06 04:19:55

标签: python google-app-engine xmpp xmpppy

嘿伙计们, 在向app引擎的xmpp客户端发送消息时,我似乎无法使用xmpppy客户端。 我没有收到任何错误。这些消息并没有到达那里。 从app引擎的客户端发送消息到sl4a客户端工作。 向google talk客户端发送往返于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 个答案:

答案 0 :(得分:4)

1)检查garrowsbot@gmail.com是否在cellbotmote@appspot.com的名单上。 GTalk不会传递来自未知用户的消息。 2)发送聊天类型的消息:

xmppClient.send(xmpp.Message(operator, msg, typ='chat'))

有些客户对接收没有type属性的“普通”消息反应不佳。