Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python for Google App Engine
  • Toc
  • feedback
Python for Google App Engine

Python for Google App Engine

By : Pippi
4.1 (10)
close
Python for Google App Engine

Python for Google App Engine

4.1 (10)
By: Pippi

Overview of this book

If you are a Python developer, whether you have experience in web applications development or not, and want to rapidly deploy a scalable backend service or a modern web application on Google App Engine, then this book is for you.
Table of Contents (10 chapters)
close
9
Index

Implementing the server

We will start by adding the Python code needed to handle channels on the server side. We expect the JavaScript client will make an HTTP GET request to request a channel, so we add a request handler that will create a channel and return a token in the JSON format to access it. We first import the modules needed at the top of our main.py module:

from google.appengine.api import channel
from utils import get_notification_client_id
import json

Then, we add the code for the request handler:

class GetTokenHandler(webapp2.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user is None:
            self.abort(401)

        client_id = get_notification_client_id(user)
        token = channel.create_channel(client_id, 60)

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'token': token}))

We first check that the user is logged in and return an HTTP 401: Unauthorized...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete