Using the Python Library with Google App Engine

Jeff from Optimizely pointed out that uses the socket package, whereas Google App Engine locks down arbitrary socket connections. Instead, you can make a connection over port 80 via urlfetch. Here are the changes you need to make:

  1. Remove the import socket line from the top and replace it with from google.appengine.api import urlfetch
  2. After host,port = cls._host.split(':'), replace the socket logic with the following:


# Assuming port is 80, which it is:
if int(port) == 80:
  url = 'http://' + host + '/' + type + '?' + '&'.join(query)
  raise Exception("Can only connect over port 80.")

Hope this helps - email with any questions.

Is anything on this page unclear? Suggest edits on Github!