5

I'm trying to deploy a Flask app on GAE using Windows. It runs fine locally but runs into problems when I try to run it on GAE.

First I get this error in flask\json.py:

from itsdangerous import json as _json 

ImportError: No module named itsdangerous

Downloading and unpacking https://pypi.python.org/pypi/itsdangerous in the same directory doesn't fix the issue. If I just grab itsdangerous.py and put it in the flask directory, I get:

_slash_escape = '\\/' not in _json.dumps('/') 

AttributeError: 'module' object has no attribute 'dumps'

I've read that it may be due to conflicting json.py files but I've also tried using absolute paths for the import json and it doesn't seem to make a difference.

2 Answers 2

8

You put the itsdangerous.py in the wrong directory. Because json.py and itsdangerous.py both exist in the /flask directory, itsdangerous.py will import /flask/json.py intead of the right one.

The GAE official doc mentioned a way to include 3rd-party libraries:

You can include other pure Python libraries with your application by putting the code in your application directory. If you make a symbolic link to a module's directory in your application directory, appcfg.py will follow the link and include the module in your app.

Obviously, it's a poor solution because we don't want to mix the libraries we used with the code we write. The community have found better ways.

I suggest you to use a gae-flask project template(e.g. flask-appengine-template) or at least follow some of its project structure. You can put all these 3rd-party libraries under a directory like /lib and add '/lib' to sys.path. Actually flask-appengine-template include common flask modules like itsdangerous for you by default.

sample code:

import os import sys sys.path.insert(1, os.path.join(os.path.abspath('.'), 'lib')) import application 
Sign up to request clarification or add additional context in comments.

Comments

8

Google now makes it super-easy:

https://console.developers.google.com/start/appengine

2 Comments

awesome ! this should be selected as accepted answer
Downloading the code from this link doesn't work for me (it's downloading but the files are in some wrong encoding may be). So that is why I used github github.com/GoogleCloudPlatform/appengine-try-python-flask

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.