简体   繁体   English

**类型错误:“模块”对象不可调用**-uwsgi-flask-python

[英]**TypeError: 'module' object is not callable** - uwsgi - flask - python

This is my file structure:这是我的文件结构:

|--cm
|  |--bin
|  |--include
|  |--lib
|  |--app
|  |  |--views.py
|  |  |--all Flask webapp folders
|  |--uwsgi.ini
|  |--run.py

run.py运行文件

from app import views

if __name__ == "__main__":
    views.application.run()

part of views.py: views.py 的一部分:

application = Flask(__name__)
application.debug = True
WTF_CSRF_ENABLED = True

uwsgi.ini uwsgi.ini

[uwsgi]
master = true
processes = 1
socket = /var/www/KRAKEN/public/cm/socket.sock
chmod-socket = 666
plugin = python

nginx.conf配置文件

server {
        listen 80;
        server_name server.me www.server.me;
        root /var/www/KRAKEN/public/;
        error_log /var/www/KRAKEN/public/nginx.error.log;
        location / {
           index index.php index.html index.htm;
        }

    location /cm {
        include uwsgi_params;
        uwsgi_param SCRIPT_NAME /cm;
        uwsgi_pass unix:///var/www/KRAKEN/public/cm/socket.sock;
    }

}

When i run当我跑

uwsgi --ini uwsgi.ini -w run

I get:我得到:

*** Starting uWSGI 2.0.12 (32bit) on [Mon Mar 14 15:45:13 2016] ***
compiled with version: 5.3.0 on 11 March 2016 01:01:30
os: Linux-3.14.58-1-ARCH #1 SMP Fri Dec 11 18:21:13 MST 2015
nodename: KRAKEN
machine: armv7l
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /var/www/KRAKEN/public/cm
detected binary path: /var/www/KRAKEN/public/cm/bin/uwsgi
your processes number limit is 14019
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)
*** RRDtool library available at 0x1eebe58 ***
uwsgi socket 0 bound to UNIX address socket.sock fd 3
Python version: 3.5.1 (default, Mar  6 2016, 10:14:04)  [GCC 5.3.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1efa768
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x1efa768 pid: 32487 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 32487)
spawned uWSGI worker 1 (pid: 32489, cores: 1)

Then i go to the app route and get:然后我转到应用程序路线并获得:

unable to load app 0 (mountpoint='') (callable not found or import error)

I believe there is something wrong with the callable , tried setting callable = views or callabe = app.views as shown in Flask( name ) but with no success.我相信callable 有问题,尝试设置 callable = views 或 callabe = app.views 如 Flask( name ) 所示,但没有成功。

The NGINX error log throws: NGINX 错误日志抛出:

2016/03/14 17:19:22 [error] 1434#0: *355 upstream prematurely closed connection while reading response header from upstream, client: 190.228.175.122, server: server.me, request: "GET /cm/ HTTP/1.1", upstream: "uwsgi://unix:///var/www/KRAKEN/public/cm/socket.sock:", host: "www.server.me"

Tips?提示?

EDIT: actually, changing callable = views rendered another error:编辑:实际上,更改 callable = 视图会导致另一个错误:

TypeError: 'module' object is not callable类型错误:“模块”对象不可调用

Which now I belive is a more python related issue...现在我相信这是一个与 python 相关的问题......

Edit2: i'm running under a virtual env. Edit2:我在虚拟环境下运行。

Edit3: just to clarify, the app does work when run with python run.py . Edit3:只是为了澄清,该应用程序在使用python run.py运行时确实有效。

Edit4: detail when i run the uwsgi command. Edit4:当我运行 uwsgi 命令时的详细信息。

Edit5: nginx info. Edit5: nginx 信息。

将views.py从cm移到应用程序的根目录并正常工作。

A general solution to this answer is instead of running and troubleshooting此答案的一般解决方案是运行和故障排除

uwsgi --ini uwsgi.ini -w run

Is to instead debug the errors you get from run.py.而是调试您从 run.py 获得的错误。 Give this a shot and resolve any issues -试一试并解决任何问题 -

python run.py

Flask is giving you this TypeError because whatever file that is following this pattern: Flask 给你这个 TypeError 因为任何遵循这种模式的文件:

from app import views

if __name__ == "__main__":
    views.application.run()

has an issue and wouldn't run with or without UWSGI.有问题,无论有没有 UWSGI 都不会运行。 UWSGI is hiding the real root cause behind a TypeError. UWSGI 隐藏了 TypeError 背后的真正根本原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM