TypeError: 'module' object is not callable while deploying flask app using uwsgi/nginx
TypeError: 'module' object is not callable while deploying flask app using uwsgi/nginx
我正在使用 uwsgi 和 nginx 部署一个 flask web 应用程序 tutorial。当我 运行 测试教程中提到的命令 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。虽然简单 运行ning python wsgi.py
文件在端口 5001 上,所有请求 return 响应没有任何错误。
wsgi.py
中的代码
from ds_app import factory
import ds_app as app
if __name__=="__main__":
app = factory.create_app(celery=app.celery)
app.run()
下面运行ning 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
任何人都可以帮助我为什么在 运行ning 使用 uWSGi 命令时同样的代码会出错。高度赞赏任何潜在客户。
如果 main 有效,则将代码移到外面。
from ds_app import factory
import ds_app as application
app = factory.create_app(celery=application.celery)
if __name__=="__main__":
app.run()
我正在使用 uwsgi 和 nginx 部署一个 flask web 应用程序 tutorial。当我 运行 测试教程中提到的命令 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。虽然简单 运行ning python wsgi.py
文件在端口 5001 上,所有请求 return 响应没有任何错误。
wsgi.py
from ds_app import factory
import ds_app as app
if __name__=="__main__":
app = factory.create_app(celery=app.celery)
app.run()
下面运行ning 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
任何人都可以帮助我为什么在 运行ning 使用 uWSGi 命令时同样的代码会出错。高度赞赏任何潜在客户。
如果 main 有效,则将代码移到外面。
from ds_app import factory
import ds_app as application
app = factory.create_app(celery=application.celery)
if __name__=="__main__":
app.run()