2

我正在按照本教程使用 uwsgi 和 nginx 部署烧瓶 Web 应用程序。当我运行 uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app教程中提到的命令进行测试时,它会给出错误 TypeError: 'module' object is not callable on any api requests or any end points. 尽管python wsgi.py端口 5001 上的简单运行文件,但所有请求都返回响应而没有任何错误。

代码在wsgi.py

from ds_app import factory
import ds_app as app
if  __name__=="__main__":
    app = factory.create_app(celery=app.celery)
    app.run()

运行 uwsgi 命令时的响应如下。

(venv_nsfw) ubuntu@ip-172-30-1-153:~/trell_projects/trell-ds-framework$ uwsgi --socket 0.0.0.0:5001 --protocol=http -w wsgi:app
*** Starting uWSGI 2.0.18 (64bit) on [Mon Jul 13 15:13:05 2020] ***
compiled with version: 7.5.0 on 24 April 2020 01:54:26
os: Linux-4.15.0-1058-aws #60-Ubuntu SMP Wed Jan 15 22:35:20 UTC 2020
nodename: ip-172-30-1-153
machine: x86_64
clock source: unix
detected number of CPU cores: 8
current working directory: /home/ubuntu/trell_projects/trell-ds-framework
detected binary path: /home/ubuntu/trell_projects/venv_nsfw/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 255081
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 socket 0 bound to TCP address 0.0.0.0:5001 fd 3
Python version: 3.6.9 (default, Apr 18 2020, 01:56:04)  [GCC 8.4.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x5643bd9502c0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x5643bd9502c0 pid: 11035 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 11035, cores: 1)
TypeError: 'module' object is not callable
[pid: 11035|app: 0|req: 1/1] 45.95.98.96 () {30 vars in 612 bytes} [Mon Jul 13 15:13:31 2020] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
TypeError: 'module' object is not callable
[pid: 11035|app: 0|req: 2/2] 171.51.145.232 () {32 vars in 620 bytes} [Mon Jul 13 15:14:12 2020] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
TypeError: 'module' object is not callable

任何人都可以帮助我为什么在使用 uWSGi 命令运行时相同的代码会出错。任何线索都受到高度评价。

4

1 回答 1

0

如果main工作,将代码移到外面。

from ds_app import factory
import ds_app as application
app = factory.create_app(celery=application.celery)
if  __name__=="__main__":
    app.run()
于 2020-07-22T16:23:07.130 回答