Python uwsgi nginx flask:无法加载应用程序0(装入点=';';)(未找到可调用项或导入错误)

Python uwsgi nginx flask:无法加载应用程序0(装入点=';';)(未找到可调用项或导入错误),python,docker,nginx,flask,uwsgi,Python,Docker,Nginx,Flask,Uwsgi,考虑以下文件结构: root |- app | |- api { ... } | |- logic { ... } | |- models { ... } | |- schema { ... } | |- __init__.py | |- config.py | |- sql_alchemy.py | |- utils.py |- docker-compose.yml |- Dockerfile |- main.py |- Pipfile |- Pipfile.lock |- R

考虑以下文件结构:

root
|- app
|  |- api { ... }
|  |- logic { ... }
|  |- models { ... }
|  |- schema { ... }
|  |- __init__.py
|  |- config.py
|  |- sql_alchemy.py
|  |- utils.py
|- docker-compose.yml
|- Dockerfile
|- main.py
|- Pipfile
|- Pipfile.lock
|- README.md
|- uwsgi.ini
docker compose.yml

version: '3'

services:
    app:
        restart: always
        build: .
        depends_on:
            - db
        expose:
            - "5000"
        ports:
            - "5000:5000"
    db:
        restart: always
        image: "mysql:5.7.22"
        expose:
            - "3306"
        ports:
            - "3306:3306"
        environment:
            - MYSQL_ALLOW_EMPTY_PASSWORD=yes
            - MYSQL_DATABASE=philipsonska
        volumes:
            - ./data:/var/lib/mysql
Dockerfile

FROM tiangolo/uwsgi-nginx-flask:python3.7

COPY ./app /app/app
COPY main.py uwsgi.ini /app/
COPY Pipfile Pipfile.lock /

RUN pip3 install pipenv==10.1.2
RUN pipenv install --three --system
main.py

from app import create_app

if __name__ == '__main__':
    app = create_app()

    app.run('0.0.0.0', 5000, False)
from flask import Flask
from flask_cors import CORS
from flask_jwt import JWT

from app.api import Api
from app.config import Config
from app.sql_alchemy import SQLAlchemy


db = SQLAlchemy()
jwt = JWT()
cors = CORS(supports_credentials=True)
api = Api()


def create_app(arg1,arg2) -> Flask:
    from app.logic import AuthLogic

    app = Flask(__name__)
    app.config.from_object(Config)

    jwt.identity_callback = AuthLogic.identity
    jwt.authentication_callback = AuthLogic.auth
    jwt.request_callback = AuthLogic.request
    jwt.auth_response_callback = AuthLogic.response

    api.init_app(app)
    db.init_app(app)
    jwt.init_app(app)
    cors.init_app(app)

    return app
uwsgi.ini

[uwsgi]
module = main
callable = app
app/\uuuuu init\uuuuuuuuuuuuupy

from app import create_app

if __name__ == '__main__':
    app = create_app()

    app.run('0.0.0.0', 5000, False)
from flask import Flask
from flask_cors import CORS
from flask_jwt import JWT

from app.api import Api
from app.config import Config
from app.sql_alchemy import SQLAlchemy


db = SQLAlchemy()
jwt = JWT()
cors = CORS(supports_credentials=True)
api = Api()


def create_app(arg1,arg2) -> Flask:
    from app.logic import AuthLogic

    app = Flask(__name__)
    app.config.from_object(Config)

    jwt.identity_callback = AuthLogic.identity
    jwt.authentication_callback = AuthLogic.auth
    jwt.request_callback = AuthLogic.request
    jwt.auth_response_callback = AuthLogic.response

    api.init_app(app)
    db.init_app(app)
    jwt.init_app(app)
    cors.init_app(app)

    return app
我的问题是,当我运行
docker compose-up--build
时,我得到以下错误:
无法加载应用程序0(mountpoint='')(可调用未找到或导入错误)

完整输出:

app_1  | /usr/lib/python2.7/dist-packages/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
app_1  |   'Supervisord is running as root and it is searching '
app_1  | 2019-06-26 13:06:09,439 CRIT Supervisor running as root (no user in config file)
app_1  | 2019-06-26 13:06:09,439 INFO Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
app_1  | 2019-06-26 13:06:09,451 INFO RPC interface 'supervisor' initialized
app_1  | 2019-06-26 13:06:09,451 CRIT Server 'unix_http_server' running without any HTTP authentication checking
app_1  | 2019-06-26 13:06:09,452 INFO supervisord started with pid 1
app_1  | 2019-06-26 13:06:10,454 INFO spawned: 'nginx' with pid 9
app_1  | 2019-06-26 13:06:10,458 INFO spawned: 'uwsgi' with pid 10
app_1  | [uWSGI] getting INI configuration from /app/uwsgi.ini
app_1  | [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
app_1  |
app_1  | ;uWSGI instance configuration
app_1  | [uwsgi]
app_1  | cheaper = 2
app_1  | processes = 16
app_1  | ini = /app/uwsgi.ini
app_1  | module = main
app_1  | callable = app
app_1  | ini = /etc/uwsgi/uwsgi.ini
app_1  | socket = /tmp/uwsgi.sock
app_1  | chown-socket = nginx:nginx
app_1  | chmod-socket = 664
app_1  | hook-master-start = unix_signal:15 gracefully_kill_them_all
app_1  | need-app = true
app_1  | die-on-term = true
app_1  | show-config = true
app_1  | ;end of configuration
app_1  |
app_1  | *** Starting uWSGI 2.0.18 (64bit) on [Wed Jun 26 13:06:10 2019] ***
app_1  | compiled with version: 6.3.0 20170516 on 16 May 2019 04:09:50
app_1  | os: Linux-4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
app_1  | nodename: 8119f4e0b5b1
app_1  | machine: x86_64
app_1  | clock source: unix
app_1  | pcre jit disabled
app_1  | detected number of CPU cores: 2
app_1  | current working directory: /app
app_1  | detected binary path: /usr/local/bin/uwsgi
app_1  | your memory page size is 4096 bytes
app_1  | detected max file descriptor number: 1048576
app_1  | lock engine: pthread robust mutexes
app_1  | thunder lock: disabled (you can enable it with --thunder-lock)
app_1  | uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | Python version: 3.7.3 (default, May  8 2019, 05:28:42)  [GCC 6.3.0 20170516]
app_1  | *** Python threads support is disabled. You can enable it with --enable-threads ***
app_1  | Python main interpreter initialized at 0x55dbdc52de70
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | your server socket listen backlog is limited to 100 connections
app_1  | your mercy for graceful operations on workers is 60 seconds
app_1  | mapped 1239640 bytes (1210 KB) for 16 cores
app_1  | *** Operational MODE: preforking ***
app_1  | unable to load app 0 (mountpoint='') (callable not found or import error)
app_1  | *** no app loaded. GAME OVER ***
app_1  | 2019-06-26 13:06:10,983 INFO exited: uwsgi (exit status 22; not expected)
app_1  | 2019-06-26 13:06:11,985 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
app_1  | 2019-06-26 13:06:11,987 INFO spawned: 'uwsgi' with pid 12
app_1  | [uWSGI] getting INI configuration from /app/uwsgi.ini
app_1  | [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
app_1  |
app_1  | ;uWSGI instance configuration
app_1  | [uwsgi]
app_1  | cheaper = 2
app_1  | processes = 16
app_1  | ini = /app/uwsgi.ini
app_1  | module = main
app_1  | callable = app
app_1  | ini = /etc/uwsgi/uwsgi.ini
app_1  | socket = /tmp/uwsgi.sock
app_1  | chown-socket = nginx:nginx
app_1  | chmod-socket = 664
app_1  | hook-master-start = unix_signal:15 gracefully_kill_them_all
app_1  | need-app = true
app_1  | die-on-term = true
app_1  | show-config = true
app_1  | ;end of configuration
app_1  |
app_1  | *** Starting uWSGI 2.0.18 (64bit) on [Wed Jun 26 13:06:11 2019] ***
app_1  | compiled with version: 6.3.0 20170516 on 16 May 2019 04:09:50
app_1  | os: Linux-4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
app_1  | nodename: 8119f4e0b5b1
app_1  | machine: x86_64
app_1  | clock source: unix
app_1  | pcre jit disabled
app_1  | detected number of CPU cores: 2
app_1  | current working directory: /app
app_1  | detected binary path: /usr/local/bin/uwsgi
app_1  | your memory page size is 4096 bytes
app_1  | detected max file descriptor number: 1048576
app_1  | lock engine: pthread robust mutexes
app_1  | thunder lock: disabled (you can enable it with --thunder-lock)
app_1  | uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | Python version: 3.7.3 (default, May  8 2019, 05:28:42)  [GCC 6.3.0 20170516]
app_1  | *** Python threads support is disabled. You can enable it with --enable-threads ***
app_1  | Python main interpreter initialized at 0x556f78d61e70
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | your server socket listen backlog is limited to 100 connections
app_1  | your mercy for graceful operations on workers is 60 seconds
app_1  | mapped 1239640 bytes (1210 KB) for 16 cores
app_1  | *** Operational MODE: preforking ***
app_1  | unable to load app 0 (mountpoint='') (callable not found or import error)
app_1  | *** no app loaded. GAME OVER ***
app_1  | 2019-06-26 13:06:12,496 INFO exited: uwsgi (exit status 22; not expected)
app_1  | 2019-06-26 13:06:14,501 INFO spawned: 'uwsgi' with pid 13
app_1  | [uWSGI] getting INI configuration from /app/uwsgi.ini
app_1  | [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
app_1  |
app_1  | ;uWSGI instance configuration
app_1  | [uwsgi]
app_1  | cheaper = 2
app_1  | processes = 16
app_1  | ini = /app/uwsgi.ini
app_1  | module = main
app_1  | callable = app
app_1  | ini = /etc/uwsgi/uwsgi.ini
app_1  | socket = /tmp/uwsgi.sock
app_1  | chown-socket = nginx:nginx
app_1  | chmod-socket = 664
app_1  | hook-master-start = unix_signal:15 gracefully_kill_them_all
app_1  | need-app = true
app_1  | die-on-term = true
app_1  | show-config = true
app_1  | ;end of configuration
app_1  |
app_1  | *** Starting uWSGI 2.0.18 (64bit) on [Wed Jun 26 13:06:14 2019] ***
app_1  | compiled with version: 6.3.0 20170516 on 16 May 2019 04:09:50
app_1  | os: Linux-4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
app_1  | nodename: 8119f4e0b5b1
app_1  | machine: x86_64
app_1  | clock source: unix
app_1  | pcre jit disabled
app_1  | detected number of CPU cores: 2
app_1  | current working directory: /app
app_1  | detected binary path: /usr/local/bin/uwsgi
app_1  | your memory page size is 4096 bytes
app_1  | detected max file descriptor number: 1048576
app_1  | lock engine: pthread robust mutexes
app_1  | thunder lock: disabled (you can enable it with --thunder-lock)
app_1  | uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | Python version: 3.7.3 (default, May  8 2019, 05:28:42)  [GCC 6.3.0 20170516]
app_1  | *** Python threads support is disabled. You can enable it with --enable-threads ***
app_1  | Python main interpreter initialized at 0x55d7a1bc2e70
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | your server socket listen backlog is limited to 100 connections
app_1  | your mercy for graceful operations on workers is 60 seconds
app_1  | mapped 1239640 bytes (1210 KB) for 16 cores
app_1  | *** Operational MODE: preforking ***
app_1  | unable to load app 0 (mountpoint='') (callable not found or import error)
app_1  | *** no app loaded. GAME OVER ***
app_1  | 2019-06-26 13:06:14,848 INFO exited: uwsgi (exit status 22; not expected)
app_1  | 2019-06-26 13:06:17,856 INFO spawned: 'uwsgi' with pid 14
app_1  | [uWSGI] getting INI configuration from /app/uwsgi.ini
app_1  | [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
app_1  |
app_1  | ;uWSGI instance configuration
app_1  | [uwsgi]
app_1  | cheaper = 2
app_1  | processes = 16
app_1  | ini = /app/uwsgi.ini
app_1  | module = main
app_1  | callable = app
app_1  | ini = /etc/uwsgi/uwsgi.ini
app_1  | socket = /tmp/uwsgi.sock
app_1  | chown-socket = nginx:nginx
app_1  | chmod-socket = 664
app_1  | hook-master-start = unix_signal:15 gracefully_kill_them_all
app_1  | need-app = true
app_1  | die-on-term = true
app_1  | show-config = true
app_1  | ;end of configuration
app_1  |
app_1  | *** Starting uWSGI 2.0.18 (64bit) on [Wed Jun 26 13:06:17 2019] ***
app_1  | compiled with version: 6.3.0 20170516 on 16 May 2019 04:09:50
app_1  | os: Linux-4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
app_1  | nodename: 8119f4e0b5b1
app_1  | machine: x86_64
app_1  | clock source: unix
app_1  | pcre jit disabled
app_1  | detected number of CPU cores: 2
app_1  | current working directory: /app
app_1  | detected binary path: /usr/local/bin/uwsgi
app_1  | your memory page size is 4096 bytes
app_1  | detected max file descriptor number: 1048576
app_1  | lock engine: pthread robust mutexes
app_1  | thunder lock: disabled (you can enable it with --thunder-lock)
app_1  | uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | Python version: 3.7.3 (default, May  8 2019, 05:28:42)  [GCC 6.3.0 20170516]
app_1  | *** Python threads support is disabled. You can enable it with --enable-threads ***
app_1  | Python main interpreter initialized at 0x561dc7635e70
app_1  | uWSGI running as root, you can use --uid/--gid/--chroot options
app_1  | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
app_1  | your server socket listen backlog is limited to 100 connections
app_1  | your mercy for graceful operations on workers is 60 seconds
app_1  | mapped 1239640 bytes (1210 KB) for 16 cores
app_1  | *** Operational MODE: preforking ***
app_1  | unable to load app 0 (mountpoint='') (callable not found or import error)
app_1  | *** no app loaded. GAME OVER ***
app_1  | 2019-06-26 13:06:18,201 INFO exited: uwsgi (exit status 22; not expected)
app_1  | 2019-06-26 13:06:19,202 INFO gave up: uwsgi entered FATAL state, too many start retries too quickly
根据,我应该将
从app import create_app
更改为
从app import create_app as application
,从uwsgi.ini中删除
callable=app
,并更改为application()。运行(…)。我试过了,它一直工作到服务器能够启动为止。我在main.py中执行了以下操作:

from app import create_app as application

if __name__ == '__main__':
    application = application()

    application.run('0.0.0.0', 5000, True)
现在我在尝试使用端点时遇到另一个错误,
TypeError:create_app()接受0个位置参数,但给出了2个


我不知道如何继续。有什么想法吗?

你能试着把
uwsgi.ini
改成

[uwsgi]
module = main
callable = app.app

uwsgi将导入
main
,从其中提取
app
,期望
app
是WSGI应用程序的实例。Flask的一个实例是WSGI应用程序。在您使用的结构中执行此操作的标准方法是

from app import create_app

app = create_app()
使用uwsgi时,您发布的代码没有调用
create\u app()
,因为正在导入
main.py
。当您实际调用
create_app()
时,需要从定义中删除未使用的
arg1
arg
参数


使事情变得混乱,特别是如果您曾经尝试过
callable=application

,但不幸的是,我仍然无法加载app 0(mountpoint='')(callable未找到或导入错误)uwsgi正在查找“app”对象而不是“application”,它是在您的main.py文件中创建的,尝试将其更改为main.app
main.py
看起来与最初一样,
app=create\u app()
app.run('0.0.0.0',5000,False)
。我应该在哪里切换到
main.app
?我尝试更改为
callable=main.app
,但它不起作用。将
def create\u app(arg1,arg2):
更改为
def create\u app():
我也尝试过,这实际上是原始代码,但当我得到
TypeError:create\u app()时,我尝试过更改它接受0个位置参数,但从您的解决方案中给出了2个
,我能够计算出,如果name\uuuu=='\uu main\uuuu':,我应该将
app=create\u app()
移到(上面)
外部,然后它工作了(当我删除
arg1,arg2
)。非常感谢。