TypeError: объект 'module' не может быть вызван при развертывании приложения flask с использованием uwsgi / nginx - PullRequest
1 голос
/ 13 июля 2020

Я развертываю веб-приложение flask с использованием uwsgi и nginx, следуя этому руководству . Когда я запускаю команду uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app, как указано в учебнике по тестированию, она выдает ошибку TypeError: объект 'module' не может быть вызван ни при каких запросах api или каких-либо конечных точках. Несмотря на простой запуск файла 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. Любые лиды высоко оценены.

1 Ответ

0 голосов
/ 22 июля 2020

Перемещение кода наружу, если основной сработал.

from ds_app import factory
import ds_app as application
app = factory.create_app(celery=application.celery)
if  __name__=="__main__":
    app.run()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...