类型错误:';模块';对象在使用uwsgi/nginx部署flask应用程序时不可调用

类型错误:';模块';对象在使用uwsgi/nginx部署flask应用程序时不可调用,nginx,flask,digital-ocean,uwsgi,uwsgi-stats-server,Nginx,Flask,Digital Ocean,Uwsgi,Uwsgi Stats Server,下面我将使用uwsgi和nginx部署一个flask web应用程序。当我运行测试教程中提到的命令uwsgi--socket 0.0.0.0:5000--protocol=http-w wsgi:app时,它给出了错误类型error:“module”对象不能在任何api请求或任何端点上调用。尽管在端口5001上运行python wsgi.py文件很简单,但所有请求都返回响应,没有任何错误 代码位于wsgi.py from ds_app import factory import ds_app a

下面我将使用uwsgi和nginx部署一个flask web应用程序。当我运行测试教程中提到的命令
uwsgi--socket 0.0.0.0:5000--protocol=http-w wsgi:app
时,它给出了错误类型error:“module”对象不能在任何api请求或任何端点上调用。尽管在端口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命令运行时,同样的代码会出现错误。高度赞赏任何潜在客户。

如果main有效,则将代码移到外部

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

ds\U应用程序
模块导入
factory
,然后再次导入
ds\U应用程序
模块,将其别名为
app
。您可以从语句中删除
,然后使用
app.factory
。您将
ds\u app
模块别名为
app
,然后创建一个名为
app
的变量(覆盖导入并覆盖
app.芹菜的值)。
factory
(使用
factory.create\u app
)和
app
(使用
app.run
)都不可调用。请在代码中尝试
print(type(factory))
print(type(app))
,以帮助您了解错误所在。谢谢。如果main工作,则将代码移到外部。