GCM通知与Python XMPP [英] GCM Notifications with Python XMPP

查看:133
本文介绍了GCM通知与Python XMPP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google提供了一个python 代码示例,用于使用可扩展消息发送GCM通知和存在协议(XMPP)。该指南没有具体提及' import xmpp '来自何处。然而,这与 xmpppy 密切相关。

不幸的是,这个xmpppy项目似乎在很多年前就被抛弃了。最后一个版本是在2009年。难怪与当前版本的openssl不兼容

  Traceback(最近调用最后一次):
文件google_ccs.py,第54行,位于< module>
client.connect(server =(SERVER,PORT),secure = 1,use_srv = False)
文件/usr/local/virtualenv-django18/local/lib/python2.7/site-packages如果不是CommonClient.connect(self,server,proxy,secure,use_srv)或secure<> None并且不安全:return self.connected $ b $,则连接
中的/xmpp/client.py b文件/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/client.py,第178行,连接
transports.TLS()。PlugIn(self,现在= 1)
文件/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/transports.py,第281行,在PlugIn
如果现在:返回self._startSSL()
文件/usr/local/virtualenv-django18/local/lib/python2.7/site-packages/xmpp/transports.py,行316,在_startSSL
tcpsock ._sslIssuer = tcpsock._sslObj.issuer()
AttributeError:'_ssl._SSLSocket'对象没有属性'issuer'

这个特定的堆栈跟踪在Amazon Linux上(2015年9月发布)。的OpenSSL 1.0.1k-14.89.amzn1.x86_64。它也可以在其他发行版上看到。事实上,在其他具有xmpppy作为依赖项目的项目中可以看到几乎相同的堆栈跟踪。如何解决这个问题?

解决方案

第一个解决方案是修补 xmpp / transports.py 该补丁来自 free-bsd 但是可以在linux上运行。第二种解决方案是切换到 xmpppy / a>没有这个问题。您可以按如下方式安装它。

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

python setup.py build
python setup.py install

现在SSL错误消失了。您可以对使用2年前而不是7年前最后更新的代码的知识感到满意!此解决方案适用于任何以xmpppy作为依赖关系的项目,并不仅限于GCM。



这两个解决方案都在 Eventlet错误报告

更新:
您可以甚至使用pip来安装fork。

  pip install https://github.com/ArchipelProject/xmpppy/archive/master。 zip 


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
    transports.TLS().PlugIn(self,now=1)
  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?

解决方案

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

这篇关于GCM通知与Python XMPP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆