Uploading to the local App Engine development server

For a while I’ve been working with Google’s App Engine to power a new web site. Following some recent changes that were made to the database, I needed to host a local copy of the database in the development server for testing. In theory this isn’t too hard, I was able to find the instructions easily enough at this blog. But times have changed since 2011 and when trying to upload to the development server, I kept finding my session unauthenticated:


[INFO    ] Opening database: bulkloader-progress-20160505.162828.sql3
2016-05-05 16:28:30,771 INFO client.py:578 Refreshing due to a 401 (attempt 1/2)
2016-05-05 16:28:30,772 INFO client.py:804 Refreshing access_token

After trying a few different ways to get around the authentication, I found myself agreeing with the current bug report over here, which suggests that you simply force the development server to always force the remote Python API to recognise the current session as admin. Inside the file handler.py in google.appengine.ext.remote_api, you can add this sneaky work around near line 318:


def CheckIsAdmin(self):
    return True  # add this line
    user_is_authorized = False
    if users.is_current_user_admin():
        user_is_authorized = True

Then restart the development server and redo the upload


appcfg.py upload_data --url=http://localhost:8080/_ah/remote_api --file=database.sqlite --application=dev~project

Once the upload is done, you can comment out this little addition to protect your development environment from an accidental mistake.

And I’m now beginning to appreciate the irony of writing ‘good code’ in your blog name when this is the first post…


Update 14/5/16: Authentication errors can also be triggered when a file is uploaded a second time, or else when the file is very large. Typically these result in a new certificate being issued, for the devserver/client communication, but these seem to get confused when multiple threads are being run. If uploads aren’t completing, try adding the–num_threads=1 argument to your upload command.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s