为什么mysql python flask网站不能在heroku上运行?

ghhkc1vu  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(152)

所以我把我的网站上传到了heroku。我正在使用python flask和mysql数据库。它在我的本地计算机上运行良好。但在heroku上,它给了我一个错误信息:

PS C:\Users\uSDDE\iptutorial> heroku logs
 »   Warning: heroku update available from 7.53.0 to 7.56.0.
2021-07-08T13:20:35.536729+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception
2021-07-08T13:20:35.536729+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2021-07-08T13:20:35.536737+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
2021-07-08T13:20:35.536737+00:00 app[web.1]: raise value
2021-07-08T13:20:35.536738+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
2021-07-08T13:20:35.536738+00:00 app[web.1]: rv = self.dispatch_request()
2021-07-08T13:20:35.536738+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
2021-07-08T13:20:35.536739+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2021-07-08T13:20:35.536739+00:00 app[web.1]: File "/app/app/routes.py", line 27, in index
2021-07-08T13:20:35.536740+00:00 app[web.1]: return render_template('index.html', title='Home')
2021-07-08T13:20:35.536741+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/templating.py", line 136, in render_template
2021-07-08T13:20:35.536741+00:00 app[web.1]: ctx.app.update_template_context(context)
2021-07-08T13:20:35.536741+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 838, in update_template_context
2021-07-08T13:20:35.536742+00:00 app[web.1]: context.update(func())
2021-07-08T13:20:35.536742+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_login/utils.py", line 379, in _user_context_processor
2021-07-08T13:20:35.536743+00:00 app[web.1]: return dict(current_user=_get_user())
2021-07-08T13:20:35.536743+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_login/utils.py", line 346, in _get_user
2021-07-08T13:20:35.536743+00:00 app[web.1]: current_app.login_manager._load_user()
2021-07-08T13:20:35.536744+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_login/login_manager.py", line 318, in _load_user
2021-07-08T13:20:35.536744+00:00 app[web.1]: user = self._user_callback(user_id)
2021-07-08T13:20:35.536745+00:00 app[web.1]: File "/app/app/models.py", line 57, in load_user
2021-07-08T13:20:35.536745+00:00 app[web.1]: return User2.query.get(int(id))
2021-07-08T13:20:35.536745+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 1018, in get
2021-07-08T13:20:35.536746+00:00 app[web.1]: return self._get_impl(ident, loading.load_on_pk_identity)
2021-07-08T13:20:35.536746+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
2021-07-08T13:20:35.536747+00:00 app[web.1]: return db_load_fn(self, primary_key_identity)
2021-07-08T13:20:35.536747+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
2021-07-08T13:20:35.536747+00:00 app[web.1]: return q.one()
2021-07-08T13:20:35.536748+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3490, in one
2021-07-08T13:20:35.536748+00:00 app[web.1]: ret = self.one_or_none()
2021-07-08T13:20:35.536749+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
2021-07-08T13:20:35.536749+00:00 app[web.1]: ret = list(self)
2021-07-08T13:20:35.536749+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
2021-07-08T13:20:35.536750+00:00 app[web.1]: return self._execute_and_instances(context)
2021-07-08T13:20:35.536750+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3556, in _execute_and_instances
2021-07-08T13:20:35.536751+00:00 app[web.1]: conn = self._get_bind_args(
2021-07-08T13:20:35.536751+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3571, in _get_bind_args
2021-07-08T13:20:35.536751+00:00 app[web.1]: return fn(
2021-07-08T13:20:35.536752+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3550, in _connection_from_session
2021-07-08T13:20:35.536752+00:00 app[web.1]: conn = self.session.connection(**kw)
2021-07-08T13:20:35.536752+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1142, in
connection
2021-07-08T13:20:35.536753+00:00 app[web.1]: return self._connection_for_bind(
2021-07-08T13:20:35.536753+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1150, in
_connection_for_bind
2021-07-08T13:20:35.536754+00:00 app[web.1]: return self.transaction._connection_for_bind(
2021-07-08T13:20:35.536754+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 433, in _connection_for_bind
2021-07-08T13:20:35.536754+00:00 app[web.1]: conn = bind._contextual_connect()
2021-07-08T13:20:35.536755+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2302, in
_contextual_connect
2021-07-08T13:20:35.536755+00:00 app[web.1]: self._wrap_pool_connect(self.pool.connect, None),
2021-07-08T13:20:35.536756+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2339, in
_wrap_pool_connect
2021-07-08T13:20:35.536756+00:00 app[web.1]: Connection._handle_dbapi_exception_noconnection(
2021-07-08T13:20:35.536758+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1583, in
_handle_dbapi_exception_noconnection
2021-07-08T13:20:35.536758+00:00 app[web.1]: util.raise_(
2021-07-08T13:20:35.536758+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
2021-07-08T13:20:35.536759+00:00 app[web.1]: raise exception
2021-07-08T13:20:35.536759+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2336, in
_wrap_pool_connect
2021-07-08T13:20:35.536759+00:00 app[web.1]: return fn()
2021-07-08T13:20:35.536760+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 364, in connect
2021-07-08T13:20:35.536760+00:00 app[web.1]: return _ConnectionFairy._checkout(self)
2021-07-08T13:20:35.536765+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
2021-07-08T13:20:35.536766+00:00 app[web.1]: fairy = _ConnectionRecord.checkout(pool)
2021-07-08T13:20:35.536766+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
2021-07-08T13:20:35.536767+00:00 app[web.1]: rec = pool._do_get()
2021-07-08T13:20:35.536767+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
2021-07-08T13:20:35.536767+00:00 app[web.1]: self._dec_overflow()
2021-07-08T13:20:35.536768+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68,
in __exit__
2021-07-08T13:20:35.536768+00:00 app[web.1]: compat.raise_(
2021-07-08T13:20:35.536768+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
2021-07-08T13:20:35.536769+00:00 app[web.1]: raise exception
2021-07-08T13:20:35.536769+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get
2021-07-08T13:20:35.536770+00:00 app[web.1]: return self._create_connection()
2021-07-08T13:20:35.536770+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
2021-07-08T13:20:35.536770+00:00 app[web.1]: return _ConnectionRecord(self)
2021-07-08T13:20:35.536771+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 440, in __init__
2021-07-08T13:20:35.536771+00:00 app[web.1]: self.__connect(first_connect_check=True)
2021-07-08T13:20:35.536772+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
2021-07-08T13:20:35.536772+00:00 app[web.1]: pool.logger.debug("Error on connect(): %s", e)
2021-07-08T13:20:35.536773+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68,
in __exit__
2021-07-08T13:20:35.536773+00:00 app[web.1]: compat.raise_(
2021-07-08T13:20:35.536774+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
2021-07-08T13:20:35.536774+00:00 app[web.1]: raise exception
2021-07-08T13:20:35.536774+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 656, in __connect
2021-07-08T13:20:35.536775+00:00 app[web.1]: connection = pool._invoke_creator(self)
2021-07-08T13:20:35.536775+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
2021-07-08T13:20:35.536776+00:00 app[web.1]: return dialect.connect(*cargs,**cparams)
2021-07-08T13:20:35.536776+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 508, in connect
2021-07-08T13:20:35.536776+00:00 app[web.1]: return self.dbapi.connect(*cargs,**cparams)
2021-07-08T13:20:35.536777+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/mysql/connector/__init__.py", line 179, in connect
2021-07-08T13:20:35.536777+00:00 app[web.1]: return MySQLConnection(*args,**kwargs)
2021-07-08T13:20:35.536777+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/mysql/connector/connection.py", line 95, in __init__
2021-07-08T13:20:35.536778+00:00 app[web.1]: self.connect(**kwargs)
2021-07-08T13:20:35.536778+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/mysql/connector/abstracts.py", line 716, in connect
2021-07-08T13:20:35.536779+00:00 app[web.1]: self._open_connection()
2021-07-08T13:20:35.536779+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/mysql/connector/connection.py", line 206,
in _open_connection
2021-07-08T13:20:35.536780+00:00 app[web.1]: self._socket.open_connection()
2021-07-08T13:20:35.536780+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/mysql/connector/network.py", line 511, in
open_connection
2021-07-08T13:20:35.536780+00:00 app[web.1]: raise errors.InterfaceError(
2021-07-08T13:20:35.536782+00:00 app[web.1]: sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) 2003: Can't connect to MySQL server on 'localhost:3306' (111 Connection refused)
2021-07-08T13:20:35.536782+00:00 app[web.1]: (Background on this error at: http://sqlalche.me/e/13/rvf5)
2021-07-08T13:20:35.538388+00:00 heroku[router]: at=info method=GET path="/" host=iptutorial2.herokuapp.com request_id=986999dc-cd77-46e0-88fd-83de35567e36 fwd="86.190.136.60" dyno=web.1 connect=1ms service=431ms status=500 bytes=477 protocol=https
2021-07-08T13:20:35.543924+00:00 app[web.1]: 10.30.27.229 - - [08/Jul/2021:13:20:35 +0000] "GET / HTTP/1.1" 500 290 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"

那么这意味着什么呢??我能做些什么呢?我怎样才能修好它??我以前使用的是mysql lite数据库,并将其上传到heroku上,它可以正常工作,但现在我将其更改为mysql数据库,它不再工作了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题