I'm implementing a Google Cloud Messaging XMPP server in Python. I can connect and authenticate to the GCM, however I use self.ssl_sock.recv(1024) which isn't good, but works for the auth.
However when I later on want to receive messages from the GCM I read on the socket, but how many bytes do I read?? I can't find anything in the xmpp docs about some kind of header which tell length of packet/data.
def read_from_socket(self):
data = self.ssl_sock.recv(??)
self.handle_message(data)
XMPP does not use framing, so there is no header. You need to parse the XML stream using a streaming (e.g SAX) XML parser, such as expat. The XMPP equivalent of a "packet" can be determined by tracking the depth of the parser tree.
However if you're new to XMPP, I strongly recommend using library instead of trying to write all this correctly from scratch yourself.
You're using Python. A good library to start with is SleekXMPP, which is also the library used for code examples in XMPP: The Definitive Guide book.
More info:
Github: https://github.com/fritzy/SleekXMPP
Docs: http://sleekxmpp.readthedocs.org/en/latest/
PyPi: https://pypi.python.org/pypi/sleekxmpp
Related
Is there a way to receive and process packets intercepted in http-toolkit programmatically using python?
Is there any internal API I access?
Ideally I would like to receive the packets in a JSON or HAR format.
Within HTTP Toolkit itself, this isn't possible right now, but it is planned in future. You can +1 on the issue to vote for it here: https://github.com/httptoolkit/httptoolkit/issues/37. With that, you'd be able to add your own scripts within HTTP Toolkit which could process or store packets elsewhere any way you like, including sending them to a Python process.
In the meantime, this may be possible using Mockttp. Mockttp is the internals of HTTP Toolkit as an open-source JavaScript library that you can use to build your own fully scriptable proxy, and once that's working you can easily add logic to forward packets to Python on top of that. There's a getting started guide here: https://httptoolkit.tech/blog/javascript-mitm-proxy-mockttp/.
This is similar to How to set/access outlook DoNotForward property in Microsoft exchange service but I want to use the exchangelib Python module to send emails.
The building blocks and links to documentation are available in this exhangelib issue: https://github.com/ecederstrand/exchangelib/issues/540
In short, it's really tricky to do if you are not using a Microsoft-supplied library. You have to build a binary message with all sorts of magic variables and send that as a custom extended property. Plus you have to implement the client-side encryption needed by EWS rights management.
AFAIK, no-one has attempted a Python solution yet, and a full solution would require quite a bit of work.
I have a python GAE service, and I want to push notifications from the server to devices. The tutorial available for GCM is written for Java, and runs on ant+Tomcat/Jetty+JAE. I was under the impression that GCM would be a language-agnostic web service, and that I would be able to send push notifications regarding of my server-side platform.
Was I mistaken about GCM being compatible with my python GAE
backend?
If I CAN use it with my existing server, what instructions
can I follow (or adapt) to get started with sending notifications to
a mobile client?
Sure you can. GCM has a JSON REST API that you can work against. First you need to register you project here: http://developer.android.com/google/gcm/gs.html.
You basically do this:
Acquire you API key from http://developer.android.com/google/gcm/gs.html#access-key
Construct your payload, a dict containing registration_ids, data etc
Using url.fetch https://developers.google.com/appengine/docs/python/urlfetch/ to send the data as a JSON string to the GCM API
Here's another question with some code. Google Cloud Messaging HTTP Error 400: Bad Request and a blogpost (in not english, i think spanish. but there some sample code) http://pforray.wordpress.com/2012/07/05/ejemplo-gcm-en-appengine-python/
Use gcm-client
pip install gcm-client
Reference:
https://pypi.python.org/pypi/gcm-client/
Here you can find a module for Python interface for sending push notifications via Pushwoosh.
https://github.com/dbtsai/python-pushwoosh
You can use it for sending messages via Pushwoosh (it's free) or adapt it for your needs.
I'm trying to write a simple mail server using Python.
I found smtpd that can be used as a simple smtp server, but I don't think it supports any form of authentication.
For pop or imap, I haven't found anything at all yet.
I do know Twisted has some support for both smtp and pop or imap, but I can't find any examples or tutorials about it.
An alternative would be to use Clojure, but I still have the same question:
Which libraries should I use and is there any documentation about them?
Here is an example from Twisted.
And the main page. Follow the link for documentation to find the example and a tutorial.
Edit:
Check the attachment for this ticket for an example IMAP server. Definitely read the thread as it talks about the shortcomings of the example.
A bit late probably but for experimentation you might also want to check pymta which is a pure-python SMTP implementation I'm using for some experiments/testing. It supports SMTP basic auth. Documentation should be at a 'decent' level, check the examples directory and the unit tests-
For anything production-related I'd go for twisted if you don't mind the asynchronous nature.
im using python API in our research project.i read lot of ppt and material, and finally understand this concept now i have task to execute simple function which is chek user credential thorough openid provider and return successful after the valid user check.....
To add to the recommendation of the Python OpenID library: their docs pages for the server and consumer modules both have useful Overview sections which you should read as a good starting point. The examples directory is also useful; I've written things starting from server.py and consumer.py from there.
Why not use Python OpenID library?