【问题标题】:simple Bottle app with uWSGI not working (returns 404)带有 uWSGI 的简单 Bottle 应用程序不工作(返回 404)
【发布时间】:2014-07-16 23:45:01
【问题描述】:

我有一个用 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 not found 错误。

这是来自 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)

【问题讨论】:

  • 您的路线设置为/hello127.0.0.1:8000/hello 有效吗?
  • @Jan 下面的解决方案有效。显然,当被uWSGI调用时,所有函数都需要有app。前缀。

标签: python uwsgi bottle


【解决方案1】:

这里是更正的代码:

import bottle

app = application = bottle.Bottle()

@app.route('/hello')
def hello():
    return "hello world"

if __name__ == '__main__':
    app.run(port=8080, debug=True)

【讨论】:

    猜你喜欢
    • 2014-04-30
    • 1970-01-01
    • 2013-06-18
    • 2016-07-15
    • 1970-01-01
    • 2019-03-28
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多