使用Google GCM的Xmpp Python客户端

时间:2013-10-30 16:03:43

标签: python xmpp google-cloud-messaging

我想实施一个连接Google Cloud Messaging的XMPP客户端。

我已经拿起了图书馆sleekxmpp。

在连接/身份验证期间,我的客户端发送GCM所需的第一个流:

<stream:stream to='gcm.googleapis.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>

但是,库无法解析答案,我收到错误:

DEBUG    Connecting to [2404:6800:4008:c00::bc]:5235
DEBUG     ==== TRANSITION disconnected -> connected
DEBUG    Starting HANDLER THREAD
DEBUG    Loading event runner
DEBUG    SEND (IMMED): <stream:stream to='gcm.googleapis.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>
ERROR    Error reading from XML stream.
DEBUG    reconnecting...
DEBUG    SEND (IMMED): </stream:stream>
INFO     Waiting for </stream:stream> from server
DEBUG     ==== TRANSITION connected -> disconnected
DEBUG    connecting...

任何人都知道我为什么会这样做?

任何与GCM的Python XMPP连接的例子都可能受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

您必须将use_ssl标志设置为True

xmpp = ClientXMPP('PROJECT_ID@gcm.googleapis.com', 'API_KEY')
xmpp.connect(address=('gcm.googleapis.com', 5235), use_ssl=True)