无法在apache2中运行烧瓶

时间:2020-01-03 16:36:53

标签: python flask mod-wsgi wsgi

我想将flask应用程序部署到ubuntu apache2服务器。我做了什么:

1。创建了git存储库并将烧瓶文件上传到git,但 venv文件夹除外(因为那里有.bat,.exe文件)。

2。打开的Ubuntu VPS服务器安装了git,apache2,apache2-dev,python3.7,python3.7-dev,libapache2-mod-wsgi-py3,python-virtualenv。

3。克隆项目并cd project_name/进入该项目,而不是创建虚拟环境python -m venv venv

4。激活了虚拟环境并安装了烧瓶,firebase-admin pip install flask firebase-admin

5。 Flask应用程序文件 madad_admin.py (我的项目内容的主文件):

import os, firebase_admin
from flask import Flask, render_template, request, jsonify, url_for
from firebase_admin import  credentials, firestore

app = Flask(__name__)

cred = credentials.Certificate('./GenerateAdminSDKKey.json')
firebase_admin.initialize_app(cred)

db = firestore.client()

@app.route('/')
def index():
    users_ref = db.collection('users')
    docs = users_ref.get()
    for doc in docs:
        print('{}'.format(doc.to_dict()))
    return render_template('index.html')

if __name__ == "__main__":
    app.run(debug=True) 

6。创建了 madad_admin.wsgi 文件竞争

#! /usr/bin/python3.7
import sys

sys.path.append('/workspace/sites/madad_admin/venv/lib/python3.7/site-packages')

sys.path.insert(0, "/workspace/sites/madad_admin")

from madad_admin import app as application

7。在 / etc / apache2 / site-available 文件夹名称为 madad.conf 的目录中创建的apache2配置文件:

<VirtualHost *:80>

        WSGIDaemonProcess madad_admin user=www-data group=www-data threads=5
        WSGIScriptAlias / /workspace/sites/madad_admin/madad_admin.wsgi
        DocumentRoot /workspace/sites/madad_admin

        <Directory /workspace/sites/madad_admin>
            WSGIProcessGroup madad_admin
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
            Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

启用了

a2ensite madad.conf 禁用默认的一个。

问题是,如果我在浏览器中打开应用程序,则会显示内部服务器错误500 ,并且日志文件显示以下内容:

[Fri Jan 03 15:56:35.801841 2020] [wsgi:error] [pid 6119:tid 140690503243520] [remote 82.215.100.100:17748]   File "/workspace/sites/madad_admin/madad_admin.py", line 3, in <module>
[Fri Jan 03 15:56:35.801845 2020] [wsgi:error] [pid 6119:tid 140690503243520] [remote 82.215.100.100:17748]     from firebase_admin import  credentials, firestore
[Fri Jan 03 15:56:35.801850 2020] [wsgi:error] [pid 6119:tid 140690503243520] [remote 82.215.100.100:17748]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/firebase_admin/firestore.py", line 28, in <module>
[Fri Jan 03 15:56:35.801854 2020] [wsgi:error] [pid 6119:tid 140690503243520] [remote 82.215.100.100:17748]     raise ImportError('Failed to import the Cloud Firestore library for Python. Make sure '
[Fri Jan 03 15:56:35.801862 2020] [wsgi:error] [pid 6119:tid 140690503243520] [remote 82.215.100.100:17748] ImportError: Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.
[Fri Jan 03 15:58:04.585572 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] mod_wsgi (pid=6119): Target WSGI script '/workspace/sites/madad_admin/madad_admin.wsgi' cannot be loaded as Python module.
[Fri Jan 03 15:58:04.585623 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] mod_wsgi (pid=6119): Exception occurred processing WSGI script '/workspace/sites/madad_admin/madad_admin.wsgi'.
[Fri Jan 03 15:58:04.585842 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] Traceback (most recent call last):
[Fri Jan 03 15:58:04.585869 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/firebase_admin/firestore.py", line 22, in <module>
[Fri Jan 03 15:58:04.585874 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     from google.cloud import firestore # pylint: disable=import-error,no-name-in-module
[Fri Jan 03 15:58:04.585880 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/google/cloud/firestore.py", line 18, in <module>
[Fri Jan 03 15:58:04.585885 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     from google.cloud.firestore_v1 import __version__
[Fri Jan 03 15:58:04.585890 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 22, in <module>
[Fri Jan 03 15:58:04.585904 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     from google.cloud.firestore_v1._helpers import GeoPoint
[Fri Jan 03 15:58:04.585909 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 21, in <module>
[Fri Jan 03 15:58:04.585914 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     import grpc
[Fri Jan 03 15:58:04.585919 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/grpc/__init__.py", line 23, in <module>
[Fri Jan 03 15:58:04.585922 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     from grpc._cython import cygrpc as _cygrpc
[Fri Jan 03 15:58:04.585935 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] ImportError: cannot import name 'cygrpc'
[Fri Jan 03 15:58:04.585941 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]
[Fri Jan 03 15:58:04.585945 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] During handling of the above exception, another exception occurred:
[Fri Jan 03 15:58:04.585948 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]
[Fri Jan 03 15:58:04.585953 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] Traceback (most recent call last):
[Fri Jan 03 15:58:04.585966 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/madad_admin.wsgi", line 8, in <module>
[Fri Jan 03 15:58:04.585970 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     from madad_admin import app as application
[Fri Jan 03 15:58:04.585975 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/madad_admin.py", line 3, in <module>
[Fri Jan 03 15:58:04.585979 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     from firebase_admin import  credentials, firestore
[Fri Jan 03 15:58:04.585984 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]   File "/workspace/sites/madad_admin/venv/lib/python3.7/site-packages/firebase_admin/firestore.py", line 28, in <module>
[Fri Jan 03 15:58:04.585988 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620]     raise ImportError('Failed to import the Cloud Firestore library for Python. Make sure '
[Fri Jan 03 15:58:04.585996 2020] [wsgi:error] [pid 6119:tid 140690536814336] [remote 82.215.100.100:17620] ImportError: Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.

但所有软件包已安装在虚拟环境中

在运行时使用python madad_admin.py命令 的所有操作 wsgi中的某些错误。谢谢!

0 个答案:

没有答案