简体   繁体   中英

Send a xmpp message using xmmp python library and google app engine

I'm trying to send a message using xmpp and google app engine. I'm using xmpp library for python. My code is the following:

import webapp2
import xmpp

_SERVER = 'serverdomain'

class MainPage(webapp2.RequestHandler):
    def post(self):

        msg = 'hello'

        global username 
        username = 'user'
        global passwd
        passwd = 'ssdsd'

        global xmppClient
        global to
        to='toAddress' 

        jid = xmpp.protocol.JID(username)
        xmppClient = xmpp.Client(jid.getDomain(),debug=[])
        xmppClient.connect(server=_SERVER)
        xmppClient.auth(username, passwd, 'botty')
        xmppClient.sendInitPresence()
        self.response.out.write('me conecte '+xmppClient.isConnected())
        xmppClient.send(xmppClient.Message(to, msg, type='chat'))

app = webapp2.WSGIApplication([ ('/', MainPage)], debug=True)

When I execute my test I obtain the following error

ImportError: No module named xmpp

over and over again. I put in pythonpath the .egg xmpp library and eclipse recognized it so I can use CTRL+TAB to autocomplete., that indicates me the the editor recognize the library but no the server (GAE) so maybe I need to add the library to the server and compile it. Is that a good idea? any other server suggestion? I need help please.

Thanks.

In Debian, had the same problem. In my case, I solved it installing the python-xmpp package: apt-get install python-xmpp

I hope it help you

For package details, see here: https://packages.debian.org/sid/python/python-xmpp

Looks like your import path is incomplete. Try:

from google.appengine.api import xmpp

Instead of

import xmpp

Lots more detail here

Take a look at other questions about setting up third party libraries for GAE. Note that if the xmpp library is not pure python (ie uses native code), you won't be able to use it.

https://stackoverflow.com/search?q=google-app-engine+python+third+party+libraries

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM