problems deploying bottle application with google app engine

帅比萌擦擦* 提交于 2019-12-23 21:14:45

问题


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')

回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/12662972/problems-deploying-bottle-application-with-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!