Python xmpppy client not sending message to appengine xmpp client

末鹿安然 提交于 2019-12-08 09:45:20

问题


Hey Guys, I seem to be having trouble using the xmpppy client when sending messages to the app engine's xmpp client. I am not getting any errors. The messages just aren't arriving there. Sending messages from app engine's client to the sl4a client works. Sending messages to and from google talk's client to and from the sl4a client works as well.

Any help would be greatly appreciated.

Here is the python code

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:


1) Check that garrowsbot@gmail.com is on the roster for cellbotmote@appspot.com. GTalk won't deliver messages from unknown users. 2) Send a message of type chat:

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

Some clients do not react well to receiving "normal" messages, which don't have a type attribute.



来源:https://stackoverflow.com/questions/4611702/python-xmpppy-client-not-sending-message-to-appengine-xmpp-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!