Python XMPP 的 GCM 通知
GCM Notifications with Python XMPP
Google提供了pythoncode 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。
不幸的是,这个 xmpppy 项目似乎在很多年前就被废弃了。最后一个版本是在 2009 年。难怪与当前版本的 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'
这个特定的堆栈跟踪在 Amazon Linux(2015 年 9 月发布)上。 openssl-1.0.1k-14.89.amzn1.x86_64。它也可以在其他发行版上看到。事实上,在将 xmpppy 作为依赖项的其他项目中可以看到几乎相同的堆栈跟踪。如何解决?
第一个解决方案是修补 xmpp/transports.py
补丁来自 free-bsd 但适用于 linux。
第二种解决方案是切换到没有此问题的fork of xmpppy。您可以按如下方式安装。
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
现在 SSL 错误消失了。如果知道您使用的代码是 2 年前而不是 7 年前的最新更新,您会很高兴!此解决方案适用于任何将 xmpppy 作为依赖项的项目,而不仅限于 GCM。
两种解决方案都是在 Eventlet bug report 中发现的。
更新:
您甚至可以使用 pip 安装 fork。
pip install https://github.com/ArchipelProject/xmpppy/archive/master.zip
Google提供了pythoncode 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。
不幸的是,这个 xmpppy 项目似乎在很多年前就被废弃了。最后一个版本是在 2009 年。难怪与当前版本的 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'
这个特定的堆栈跟踪在 Amazon Linux(2015 年 9 月发布)上。 openssl-1.0.1k-14.89.amzn1.x86_64。它也可以在其他发行版上看到。事实上,在将 xmpppy 作为依赖项的其他项目中可以看到几乎相同的堆栈跟踪。如何解决?
第一个解决方案是修补 xmpp/transports.py
补丁来自 free-bsd 但适用于 linux。
第二种解决方案是切换到没有此问题的fork of xmpppy。您可以按如下方式安装。
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
现在 SSL 错误消失了。如果知道您使用的代码是 2 年前而不是 7 年前的最新更新,您会很高兴!此解决方案适用于任何将 xmpppy 作为依赖项的项目,而不仅限于 GCM。
两种解决方案都是在 Eventlet bug report 中发现的。
更新: 您甚至可以使用 pip 安装 fork。
pip install https://github.com/ArchipelProject/xmpppy/archive/master.zip