e4c5 e4c5 - 2 years ago 247
Android Question

GCM Notifications with Python XMPP

Google provides a python code sample for sending GCM notifications using the Extensible Messaging and Presence Protocol (XMPP). The guide doesn't specifically mention where the '

import xmpp
' comes from. However this tallies closely with xmpppy.

Unfortunately this xmpppy project seems to have been abandoned many years ago. The last release was in 2009. No wonder that there incompatibilities with current versions of openssl

Traceback (most recent call last):
File "google_ccs.py", line 54, in <module>
client.connect(server=(SERVER,PORT), secure=1, use_srv=False)
File "/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/client.py", line 200, in connect
if not CommonClient.connect(self,server,proxy,secure,use_srv) or secure<>None and not secure: return self.connected
File "/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/client.py", line 178, in connect
File "/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/transports.py", line 281, in PlugIn
if now: return self._startSSL()
File "/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/transports.py", line 316, in _startSSL
tcpsock._sslIssuer = tcpsock._sslObj.issuer()
AttributeError: '_ssl._SSLSocket' object has no attribute 'issuer'

This particular stacktrace was on Amazon Linux (Sept 2015 release). openssl-1.0.1k-14.89.amzn1.x86_64. It can also be seen on other distros. In fact a nearly identical stacktrace can be seen in other projects that have xmpppy as a dependency. How can this be solved?

Answer Source

The first solution is to patch xmpp/transports.py the patch comes from free-bsd but works on linux.

The second solution is to switch to a fork of xmpppy that does not have this issue. You can install it as follows.

source /myvirtualenv/bin/activate/
pip uninstall xmpppy
wget https://github.com/ArchipelProject/xmpppy/archive/master.zip
tar -xvf master
cd xmpppy-master

python setup.py build
python setup.py install

Now the SSL error goes disappears. You can be happy with the knowledge that you are using code that was last updated 2 years ago instead of seven years ago! This solution works for any project that has xmpppy as a dependency and isn't just limited to GCM.

Both solutions were discovered in an Eventlet bug report.

update: You can even use pip to install the fork.

pip install https://github.com/ArchipelProject/xmpppy/archive/master.zip
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download