簡體   English   中英

**類型錯誤:“模塊”對象不可調用**-uwsgi-flask-python

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

這是我的文件結構:

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

運行文件

from app import views

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

views.py 的一部分:

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

uwsgi.ini

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

配置文件

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;
    }

}

當我跑

uwsgi --ini uwsgi.ini -w run

我得到:

*** 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)

然后我轉到應用程序路線並獲得:

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

我相信callable 有問題,嘗試設置 callable = views 或 callabe = app.views 如 Flask( name ) 所示,但沒有成功。

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"

提示?

編輯:實際上,更改 callable = 視圖會導致另一個錯誤:

類型錯誤:“模塊”對象不可調用

現在我相信這是一個與 python 相關的問題......

Edit2:我在虛擬環境下運行。

Edit3:只是為了澄清,該應用程序在使用python run.py運行時確實有效。

Edit4:當我運行 uwsgi 命令時的詳細信息。

Edit5: nginx 信息。

將views.py從cm移到應用程序的根目錄並正常工作。

此答案的一般解決方案是運行和故障排除

uwsgi --ini uwsgi.ini -w run

而是調試您從 run.py 獲得的錯誤。 試一試並解決任何問題 -

python run.py

Flask 給你這個 TypeError 因為任何遵循這種模式的文件:

from app import views

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

有問題,無論有沒有 UWSGI 都不會運行。 UWSGI 隱藏了 TypeError 背后的真正根本原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM