【发布时间】:2020-11-02 12:04:52
【问题描述】:
我正在按照tutorial 使用 uwsgi 和 nginx 部署一个烧瓶网络应用程序。当我运行测试教程中提到的命令uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app 时,它会给出错误 TypeError: 'module' object is not callable on any api requests or any endpoints。尽管在端口 5001 上运行 python wsgi.py 文件很简单,但所有请求都返回响应而没有任何错误。
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 命令运行时相同的代码会出错。任何线索都得到高度评价。
【问题讨论】:
-
您从
ds_app模块导入factory,然后再次导入ds_app模块,将其别名为app。您可以删除from语句,然后使用app.factory。您将ds_app模块别名为app,然后创建一个名为app的变量(覆盖导入并覆盖app.celery的值)。factory(factory.create_app)和app(app.run)都不能调用。在您的代码中尝试print(type(factory))和print(type(app)),以帮助您了解哪里出了问题。 -
谢谢。如果 main 有效,则将代码移出。
标签: nginx flask digital-ocean uwsgi uwsgi-stats-server