Error trying to connect the FCM CCS server with sleekxmpp
NickName:azmeuk Ask DateTime:2016-06-24T21:21:09

Error trying to connect the FCM CCS server with sleekxmpp

I am trying to build a very simple python3 program using sleekxmpp 1.3.1 that would be able to connect the Firebase Cloud Messaging server. I have a strange Error reading from XML stream issue with the following code. How can I fix it?

We can see from the console output that STARTTLS is enabled. I found no other way than disable it from the sleekxmpp source code, but it does not solved the bug.

The first message sent seems valid according to the google documentation, still the "error reading from xml stream" appears.

The python code

FCM_SERVER_URL = "fcm-xmpp.googleapis.com"
FCM_SERVER_PORT = 5236
FCM_SECRET = "XXXXXXX"
FCM_JID = "[email protected]"

import logging, socket
from sleekxmpp.clientxmpp import ClientXMPP

class ClientComponent(ClientXMPP):
    def __init__(self):
        ClientXMPP.__init__(self, FCM_JID, FCM_SECRET)
        self.auto_reconnect = False

        server_ip = socket.gethostbyname(FCM_SERVER_URL)
        if self.connect((server_ip, FCM_SERVER_PORT), use_tls = True, reattempt = False):
            self.process(block=True)

logging.basicConfig(level=logging.DEBUG, format='%(levelname)7s %(module)12s:%(lineno)-4s %(message)s')
ClientComponent()

The console output

  DEBUG         base:328  Loaded Plugin: RFC 6120: Stream Feature: STARTTLS
  DEBUG         base:328  Loaded Plugin: RFC 6120: Stream Feature: Resource Binding
  DEBUG         base:328  Loaded Plugin: RFC 3920: Stream Feature: Start Session
  DEBUG         base:328  Loaded Plugin: RFC 6121: Stream Feature: Roster Versioning
  DEBUG         base:328  Loaded Plugin: RFC 6121: Stream Feature: Subscription Pre-Approval
  DEBUG         base:328  Loaded Plugin: RFC 6120: Stream Feature: SASL
  DEBUG    xmlstream:546  Connecting to 66.102.1.188:5236
  DEBUG    xmlstream:1162 Event triggered: connected
  DEBUG statemachine:118   ==== TRANSITION disconnected -> connected
  DEBUG    xmlstream:1444 Starting HANDLER THREAD
  DEBUG    xmlstream:1662 Loading event runner
  DEBUG    xmlstream:1309 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    xmlstream:1492 Error reading from XML stream.
  DEBUG    xmlstream:1162 Event triggered: session_end
  DEBUG    xmlstream:1309 SEND (IMMED): </stream:stream>
  DEBUG    xmlstream:1162 Event triggered: socket_error
WARNING    xmlstream:1342 Failed to send b'</stream:stream>'
  DEBUG    xmlstream:1162 Event triggered: session_end
  DEBUG    xmlstream:1397 Waiting for 3 threads to exit.
  DEBUG    xmlstream:1375 Stopped event runner thread. 2 threads remain.
  DEBUG    xmlstream:1375 Stopped send thread. 1 threads remain.
  DEBUG    scheduler:200  Quitting Scheduler thread
  DEBUG    xmlstream:1375 Stopped scheduler thread. 0 threads remain.
  DEBUG    xmlstream:1162 Event triggered: socket_error
  DEBUG    xmlstream:1162 Event triggered: disconnected
  DEBUG statemachine:118   ==== TRANSITION connected -> disconnected
   INFO    xmlstream:720  Waiting for </stream:stream> from server
  DEBUG    xmlstream:1162 Event triggered: socket_error
  DEBUG    xmlstream:1162 Event triggered: disconnected
  DEBUG statemachine:118   ==== TRANSITION disconnected -> disconnected

Copyright Notice:Content Author:「azmeuk」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/38014495/error-trying-to-connect-the-fcm-ccs-server-with-sleekxmpp

Answers
apidae 2016-07-19T14:58:07

Just for completeness, this would be an example of a working implementation:\n\nfrom sleekxmpp.clientxmpp import ClientXMPP\nimport logging\nimport socket\nimport json\nimport uuid\n\nlogging.basicConfig(level=logging.DEBUG, format=\"%(levelname)7s %(module)12s:%(lineno)-4s %(message)s\")\n\nFCM_SERVER_URL = \"fcm-xmpp.googleapis.com\"\nFCM_SERVER_PORT = 5236\nFCM_SERVER_KEY = \"XXXXXXXXXXX\" # <- Your Server Key\nFCM_SENDER_ID = \"XXXXXXXXXXX\" # <- Your Sender ID\nFCM_JID = FCM_SENDER_ID + \"@gcm.googleapis.com\"\nFCM_SERVER_IP = socket.gethostbyname(FCM_SERVER_URL)\nTOPIC = \"/topics/info\"\n\nbody = {\n \"to\": TOPIC, \n \"message_id\": uuid.uuid4().hex,\n \"data\": { \"msg\": \"This is the content\"}\n}\nmessage = \"<message><gcm xmlns='google:mobile:data'>\"+json.dumps(body)+\"</gcm></message>\"\n\nclass Client(ClientXMPP):\n def __init__(self):\n ClientXMPP.__init__(self, FCM_JID, FCM_SERVER_KEY, sasl_mech=\"PLAIN\")\n self.add_event_handler(\"session_start\", self.start)\n self.auto_reconnect = False\n self.connect((FCM_SERVER_IP, FCM_SERVER_PORT), use_tls = True, use_ssl = True, reattempt = False)\n self.process(block=True)\n def start(self, event):\n self.send_raw(message)\n self.disconnect(wait=True)\n\n\nClient()\n",


More about “Error trying to connect the FCM CCS server with sleekxmpp” related questions

Error trying to connect the FCM CCS server with sleekxmpp

I am trying to build a very simple python3 program using sleekxmpp 1.3.1 that would be able to connect the Firebase Cloud Messaging server. I have a strange Error reading from XML stream issue with...

Show Detail

How to create xmpp stanza for gcm ccs request in sleekxmpp python?

I am using sleekmpp python to communicate with my android clients using GCM / CCS. The main problem is that the data is in json format and need to be within gcm tag. How can I achieve it ? Here is...

Show Detail

Connecting to Facebook Chat using SleekXMPP

I'm using this sample code to connect to Facebook Chat over XMPP: #!/usr/bin/python import sleekxmpp import logging logging.basicConfig(level=logging.DEBUG) def session_start(event): chatbot.

Show Detail

Firebase FCM XMPP server error: connection denied due to policy

I am trying to implement an XMPP server in my Google Cloud module (endpoints) for my Android app using Android Studio in order to send downstream messages to devices. I have found an example proj...

Show Detail

FCM/GCM App Server cannot connect to FCM/GCM CCS using SSLSocket and SMACK library

I'm writing a Firebase Cloud Messaing (FCM) App server program, and encountered a connection problem when I try to connect to FCM server via XMPP connection, using SMACK library. The program fails ...

Show Detail

SleekXMPP proxy issue

I am using SleekXMPP to integrate a chat bot with Facebook. When I am not behind a proxy, I get the expected behavior. But when I am behind a proxy, the connection is not established. I took a loo...

Show Detail

Smack pitfalls and outdated code makes it nearly impossible to connect to FCM CCS

Been trying for days to connect to Firebase CCS via Smack Library. Nothing has happened. Today, I tried to set up a valueanimator with a duration of 10 seconds to try to reconnect should something ...

Show Detail

Can't authenticate to GCM CCS server

I am attempting to implement a GCM-enabled Android application but I am having trouble authenticating with the CCS server from my 3rd-party-server. import sleekxmpp as xmpp SERVER = 'gcm.googleap...

Show Detail

python sleekxmpp ping error

When I run the ping example from github, I get this AttributeError: INFO Negotiating TLS INFO Using SSL version: 1 INFO Node set to: beast@home-server/50182ab4 INFO CERT: Time until

Show Detail

Authentication with Firebase Cloud Messaging CCS using Android-Smack

I have established a "TLS" connection with FCM CCS. I assume I have established it because the logs in my Android Studio do not complain about my keystore initialization anymore. Now, after "TLS"

Show Detail