且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有Google GCM的Xmpp Python客户端

更新时间:2022-10-15 14:18:29

您必须将use_ssl标志设置为True

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


I want to implement a XMPP Client that connect the Google Cloud Messaging.

I have picked up the library sleekxmpp.

During the connection / authentication, my client sends the first stream required by GCM:

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

But, the library is not able to parse the answer and I get the error:

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...

Any one has an idea why I get this?

Any example of a python XMPP connection to the GCM might be highly appreciated.

You have to set the use_ssl flag to True

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