IssamLaradji
IssamLaradji

Reputation: 6865

How do I make bottle work with google app engine?

This is the code,

import webapp2
from framework import bottle
from framework.bottle import route, template, request, error, debug

@route('/')
def root():
         return 'hello world'
class MainHandler(webapp2.RequestHandler):
   def get(self):
        root()


app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

All the dependencies are there (framework, bottle, etc), however, when I deploy it using GAE, I just get an empty page!

Also I tried these and none of them worked, perhaps GAE changed its settings:

Upvotes: 0

Views: 2024

Answers (4)

Neil C. Obremski
Neil C. Obremski

Reputation: 20264

The Bottle class implements WSGI which works for GAE if you make it a global variable in your main script handler.

main.py

from bottle import default_app, route, run

@route('/')
def root():
  return 'hello world'

app = default_app()

app.yaml

runtime: python39

handlers:
- url: .*
  script: main.app

requirements.txt

bottle

And that's it!

I tested this on Google Cloud Shell with Bottle 0.12.19 and deploying to Google App Engine Standard.

Upvotes: 0

dario nascimento
dario nascimento

Reputation: 597

Be aware to use:

app.run(server='gae')

Otherwise bottle will try to access your system and GAE will fail

Upvotes: 1

Luca
Luca

Reputation: 1068

Another solution that worked perfectly for me: https://github.com/GoogleCloudPlatform/appengine-bottle-skeleton

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599590

You have not followed the advice in those links. Most obviously, you are simply calling root without actually returning its result back as the response. In Python, you need to explicitly use return to send a value back from a function, which you don't do in get.

You are also hopelessly confused with setting up the handlers. If you're using bottle, use it: there's no need to have webapp in the mix as well. Webapp is an alternative to bottle, not something that is baked into GAE. Your links show exactly how to do this.

Upvotes: 1

Related Questions