problems deploying bottle application with google

2019-07-19 06:00发布

newbie here--I've been trying to create a "Hello World" in bottle using google app engine. I got the "hello world" part to show up, but even on on index page, I get the following output: "Hello world!Status: 500"
If I try to add new routes (like the '/page' route), and I navigate to the new route, I get "Server error: The website encountered an error while retrieving... It may be down for maintenance or configured incorrectly." After I navigate to the improperly configured page, if I try to go back to '/', I will also receive a server error. I have placed bottle.py in my root directory. Could someone please help me to configure my file properly? Thanks!

import bottle 
from bottle import route, template, request, error, debug

@route('/')
def index():
    return "Hello World!"

@route('/page')
def page():
    return 'page!'

bottle.debug(True)
bottle.run(server='gae')

3条回答
Bombasti
2楼-- · 2019-07-19 06:00

Here's a good tutorial for bottle on GAE: http://blog.rutwick.com/use-bottle-python-framework-with-google-app-engine

DISCLAIMER: I did not run the tutorial, but it looks correct.

main.py:

from framework import bottle
from framework.bottle import route, template, request, error, debug
from google.appengine.ext.webapp.util import run_wsgi_app

@route('/')
def DisplayForm():
    message = 'Hello World'
    output = template('templates/home', data = message)
    return output

def main():
    debug(True)
    run_wsgi_app(bottle.default_app())

@error(403)
def Error403(code):
    return 'Get your codes right dude, you caused some error!'

@error(404)
def Error404(code):
    return 'Stop cowboy, what are you trying to find?'

if __name__=="__main__":
    main()

app.yaml:

application: my-bottle-app
version: 1
runtime: python
api_version: 1

handlers:
- url: /styles
  static_dir: styles

- url: /.*
  script: main.py

As you see there, are a number of differences from your sample code. The tutorial does a good job of explaining them, so I won't go into detail here.

查看更多
▲ chillily
3楼-- · 2019-07-19 06:16

This might help:

app.yaml:

application: my-app
version: 1
runtime: python27
api_version: 1
threadsafe: yes

- url: .*
  script: main.app

main.py:

import bottle

@bottle.route('/')
def root():
    return 'hello!'

bottle.run(server='gae', debug=True)
app = bottle.app()

Here's the original answer from GitHub. https://github.com/defnull/bottle/issues/401

查看更多
爷的心禁止访问
4楼-- · 2019-07-19 06:16

When using WSGI like in the App Engine + Bottle started code, you can call bottle.debug() when your code is running on the dev server:

import bottle
import os

DEBUG = os.environ.get('SERVER_SOFTWARE','').startswith('Development')  
bottle.debug(DEBUG)
app = bottle.Bottle()

And in app.yaml:

handlers:
- url: .*
  script: main.app
查看更多
登录 后发表回答