【问题标题】:"from flaskext.mysql import MySQL" causes server to show 502 bad gateway“from flaskext.mysql import MySQL”导致服务器显示 502 bad gateway
【发布时间】:2019-07-16 00:07:27
【问题描述】:

python 新手。按照几个教程在 Ubuntu 18.04 上使用 Python 3.6.7、Flask、Gunicorn、NGINX 和 MySQL 为应用程序 (ddworkflow.com) 提供服务

教程是:

https://philchen.com/2019/02/11/how-to-make-a-python-web-app-in-virtualenv-using-flask-gunicorn-nginx-on-ubuntu-18-04

https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972

我完成了第一个教程,并能够成功地提供第二个教程的基本网页。

在虚拟环境中安装所有东西,并使用pip install flask-mysql 安装了flask-mysql。

我的点子冻结显示:

Click==7.0
Flask==1.0.2
Flask-MySQL==1.4.0
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
PyMySQL==0.9.3
Werkzeug==0.14.1

在安装Flask-MySQL 之后,我通过尝试以下不同的“from”命令变体(在 python 提示符下)来测试安装:

  1. from flask.ext.mysql import MySQL
  2. from flaskext.mysql import MySQL
  3. from flask_mysql import MySQL
  4. from flaskext.mysql import MySQL

1、2、3都产生ModuleNotFoundError...唯一不抛出错误的是from flaskext.mysql import MySQL

但是,当我将 from flaskext.mysql import MySQL 添加到我的烧瓶应用程序文件 (app01.py) 时,我立即收到 502 bad gateway 错误。我的 app01.py 文件是

from flask import Flask, render_template, json, request
#from flaskext.mysql import MySQL #<--comment out or get 502 error   
hello = Flask(__name__)

@hello.route("/")
def greeting():
    return render_template('index.html')

@hello.route('/showSignUp')
def showSignUp():
    return render_template('signup.html')

@hello.route('/signUp',methods=['POST'])
def signUp(): 
    # read the posted values from the UI
    _name = request.form['inputName']
    _email = request.form['inputEmail']
    _password = request.form['inputPassword']

    # validate the received values
    if _name and _email and _password:
        return json.dumps({'html':'<span>All fields good !!</span>'})
    else:
        return json.dumps({'html':'<span>Enter the required fields</span>'})

if __name__ == "__main__":
    hello.run(host='0.0.0.0')

非常感谢任何帮助消除 502 错误以便我连接到数据库。谢谢。

【问题讨论】:

    标签: mysql nginx flask gunicorn flask-mysql


    【解决方案1】:

    这可能是 virtualenv 错误,请查看此链接:https://www.pythonanywhere.com/forums/topic/2877/

    与之前非常相似的问题:ImportError: No module named flask.ext.mysql

    【讨论】:

    • 谢谢。我会尝试并报告。干杯。
    • 谢谢,但似乎不是问题。 Flask 应用程序在导入 SQLalchemy 时加载正常,但在 MySQL 上失败下一步是测试 SQL alchemy(可能更可取)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 2016-06-15
    • 2019-03-07
    • 2021-09-11
    • 2018-01-20
    • 2017-05-10
    • 2022-07-14
    相关资源
    最近更新 更多