0
I have following code of flask with sqlalchemy along with dockerfile says about gunicorn server as well, i want to connect to MariaDB conatiner , i could not able to establish the connection, running python app.py gives below error,few says MySqldb will not support python3 since i am using python3
app.py from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy
application = Flask(name)
application.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://siemens:password@localhost/mysql' db = SQLAlchemy(application)
class User(db.Model): id = db.Column(db.Integer,primary_key=True) username = db.Column(db.String(80),unique=True) email = db.Column(db.String(120),unique=True)
def __init__(self,username,email):
self.username =username
self.email =email
def __repr__(self):
return '<User %r>' % self.username
from app import db db.create_all()
@application.route("/") def index(): return render_template("index.html")
if name == "main": application.run(host="0.0.0.0", port=80)
Docker file is below,
FROM python:3.6 ADD . /app WORKDIR /app RUN pip install flask gunicorn EXPOSE 8000 CMD ["gunicorn", "-b", "0.0.0.0:8000", "app"]
Error: /root/my_flask_app/venv/lib64/python3.6/site-packages/flask_sqlalchemy/init.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ' /root/my_flask_app/venv/lib64/python3.6/site-packages/flask_sqlalchemy/init.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ' Traceback (most recent call last): File "app.py", line 21, in from app import db File "/root/my_flask_app/flask_app/app.py", line 22, in db.create_all() File "/root/my_flask_app/venv/lib64/pythoenter code heren3.6/site-packages/flask_sqlalchemy/init.py", line 1033, in create_all self._execute_for_all_tables(app, bind, 'create_all') File "/root/my_flask_app/venv/lib64/python3.6/site-packages/flask_sqlalchemy/init.py", line 1025, in _execute_for_all_tables op(bind=self.get_engine(app, bind), **extra) File "/root/my_flask_app/venv/lib64/python3.6/site-packages/flask_sqlalchemy/init.py", line 956, in get_engine return connector.get_engine() File "/root/my_flask_app/venv/lib64/python3.6/site-packages/flask_sqlalchemy/init.py", line 561, in get_engine self._engine = rv = self._sa.create_engine(sa_url, options) File "/root/my_flask_app/venv/lib64/python3.6/site-packages/flask_sqlalchemy/init.py", line 966, in create_engine return sqlalchemy.create_engine(sa_url, **engine_opts) File "/root/my_flask_app/venv/lib64/python3.6/site-packages/sqlalchemy/engine/init.py", line 435, in create_engine return strategy.create(*args, **kwargs) File "/root/my_flask_app/venv/lib64/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 87, in create dbapi = dialect_cls.dbapi(**dbapi_args) File "/root/my_flask_app/venv/lib64/python3.6/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi return import("MySQLdb") ModuleNotFoundError: No module named 'MySQLdb'