简单的Bottle应用与uWSGI不工作(返回404)
我有一个用Bottle框架做的简单的Hello World应用:
from bottle import route, run
import bottle
app = bottle.Bottle()
@route('/hello')
def hello():
return "hello world"
if __name__ == '__main__':
run(port=8080, debug=True)
else:
application = app
当我用 python bottle-hello.py
运行时,它可以在127.0.0.1:8080上正常工作。但是当我尝试用uWSGI来运行它时:
uwsgi --http :8000 --wsgi-file bottle-hello.py
访问127.0.0.1:8000时出现404未找到的错误。
这是uWSGI输出的日志信息。最后一行显示它收到了请求,但没有返回任何内容...
*** Starting uWSGI 2.0.4 (64bit) on [Tue May 27 15:12:52 2014] ***
compiled with version: 4.8.2 on 27 May 2014 14:05:00
os: Linux-3.13.0-27-generic #50-Ubuntu SMP Thu May 15 18:06:16 UTC 2014
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /apps/bottle-hello
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7726
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 8694)
uwsgi socket 0 bound to TCP address 127.0.0.1:48544 (port auto-assigned) fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x25bb130
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72752 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x25bb130 pid: 8693 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 8693, cores: 1)
[pid: 8693|app: 0|req: 1/1] 127.0.0.1 () {36 vars in 632 bytes} [Tue May 27 15:13:01 2014] GET /hello => generated 730 bytes in 20 msecs (HTTP/1.1 404) 2 headers in 87 bytes (1 switches on core 0)
1 个回答
4
这是修正后的代码:
import bottle
app = application = bottle.Bottle()
@app.route('/hello')
def hello():
return "hello world"
if __name__ == '__main__':
app.run(port=8080, debug=True)