Я хочу, чтобы мое приложение python flask связывалось с clearDB моего веб-приложения. Обе развернуть на Heroku. Я хочу знать, возможно ли это сделать.
Это некоторые из моих кодов. я использовал все Config Vars из веб-приложения.
from flaskext.mysql import MySQL
app = Flask(__name__)
app.secret_key= 'secret key of web app'
# MySQL configurations
app.config['MYSQL_DATABASE_HOST'] = os.environ.get('DB_HOST')
app.config['MYSQL_DATABASE_PORT'] = 3306
app.config['MYSQL_DATABASE_USER'] = os.environ.get('DB_USER')
app.config['MYSQL_DATABASE_PASSWORD'] = os.environ.get('DB_PASSWORD')
app.config['MYSQL_DATABASE_DB'] = os.environ.get('DB_SCHEMA')
#init MySQL
mysql = MySQL()
mysql.init_app(app)
CHANNEL_ACCESS_TOKEN = os.environ.get('CHANNEL_ACCESS_TOKEN')
CHANNEL_SECRET = os.environ.get('CHANNEL_SECRET')
line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN)
handler = WebhookHandler(CHANNEL_SECRET)
# Handle the messages and do the responding actions here.
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
conn = mysql.connect()
c = conn.cursor()
c.execute("SELECT detect FROM park ORDER BY id DESC LIMIT 1")
lot1 = c.fetchone()
c.close()
conn.close()
это то, что я получил в журналах приложений.
a8aa0da11414 fwd="147.92.149.169" dyno=web.1 connect=1ms service=41ms status=500 bytes=451 protocol=https
2020-02-29T15:14:48.529869+00:00 app[web.1]: [2020-02-29 22:14:48,527] ERROR in app: Exception on /callback [POST]
2020-02-29T15:14:48.529879+00:00 app[web.1]: Traceback (most recent call last):
2020-02-29T15:14:48.529879+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2020-02-29T15:14:48.529880+00:00 app[web.1]: response = self.full_dispatch_request()
2020-02-29T15:14:48.529881+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2020-02-29T15:14:48.529881+00:00 app[web.1]: rv = self.handle_user_exception(e)
2020-02-29T15:14:48.529882+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2020-02-29T15:14:48.529882+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2020-02-29T15:14:48.529883+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2020-02-29T15:14:48.529883+00:00 app[web.1]: raise value
2020-02-29T15:14:48.529884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2020-02-29T15:14:48.529884+00:00 app[web.1]: rv = self.dispatch_request()
2020-02-29T15:14:48.529884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2020-02-29T15:14:48.529885+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2020-02-29T15:14:48.529885+00:00 app[web.1]: File "app.py", line 52, in callback
2020-02-29T15:14:48.529886+00:00 app[web.1]: handler.handle(body, signature)
2020-02-29T15:14:48.529886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/linebot/webhook.py", line 227, in handle
2020-02-29T15:14:48.529887+00:00 app[web.1]: func(event)
2020-02-29T15:14:48.529887+00:00 app[web.1]: File "app.py", line 60, in handle_message
2020-02-29T15:14:48.529888+00:00 app[web.1]: conn = mysql.connect()
2020-02-29T15:14:48.529888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flaskext/mysql.py", line 53, in connect
2020-02-29T15:14:48.529889+00:00 app[web.1]: return pymysql.connect(**self.connect_args)
2020-02-29T15:14:48.529889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect
2020-02-29T15:14:48.529889+00:00 app[web.1]: return Connection(*args, **kwargs)
2020-02-29T15:14:48.529890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/connections.py", line 706, in __init__
2020-02-29T15:14:48.529890+00:00 app[web.1]: self.connect()
2020-02-29T15:14:48.529891+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/connections.py", line 932, in connect
2020-02-29T15:14:48.529891+00:00 app[web.1]: self._request_authentication()
2020-02-29T15:14:48.529892+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/connections.py", line 1152, in _request_authentication
2020-02-29T15:14:48.529892+00:00 app[web.1]: auth_packet = self._read_packet()
2020-02-29T15:14:48.529892+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/connections.py", line 1014, in _read_packet
2020-02-29T15:14:48.529893+00:00 app[web.1]: packet.check_error()
2020-02-29T15:14:48.529893+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/connections.py", line 393, in check_error
2020-02-29T15:14:48.529893+00:00 app[web.1]: err.raise_mysql_exception(self._data)
2020-02-29T15:14:48.529894+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
2020-02-29T15:14:48.529894+00:00 app[web.1]: raise errorclass(errno, errval)
2020-02-29T15:14:48.529902+00:00 app[web.1]: pymysql.err.OperationalError: (1045, "Access denied for user 'u54813'@'54.173.35.197' (using password: YES)")
2020-02-29T15:14:48.530345+00:00 app[web.1]: 10.71.199.143 - - [29/Feb/2020 22:14:48] "POST /callback HTTP/1.1" 500 -
Что я здесь не так делаю? Можно ли подключиться к чужой базе приложений на героку? Если да, подскажите, пожалуйста, как это сделать.