When I run my flask application on my local machine I am able to execute queries successfully from my sql database in google cloud. However, when I deploy my app onto the google cloud platform, it throws me a "502 Bad Gateway" error once it successfully builds.
Main.py file below:
imports
from flask import Flask, render_template, request
import mysql.connector
from mysql.connector.constants import ClientFlag
configuration/setup
config = {
'user': 'user',
'password': 'passhere!',
'host': 'hosthere',
'client_flags': [ClientFlag.SSL],
'ssl_ca': 'ssl/file',
'ssl_cert': 'ssl/file',
'ssl_key': 'ssl/file',
'database': 'db'
}
cnxn = mysql.connector.connect(**config)
app = Flask(__name__, template_folder="templates")
app route
@app.route("/page/", methods=['GET', 'POST'])
def page():
if request.method == 'GET':
return render_template('/page.html')
elif request.method == 'POST':
pick = request.form["pickzip"]
pick = pick[:2]
dest = request.form["destzip"]
dest = dest[:2]
########################### SQL COMMAND GRABS LANE ####################################
cursor = cnxn.cursor()
cursor.execute("""SQL COMMAND""", (pick,dest,))
data = cursor.fetchall()
if data:
headings = ("Carrier", "Actual", "Estimated", "Load Count")
return render_template('/page.html',headings=headings, data=data)
else:
data = (["NULL", "NULL", "NULL", "NULL"])
headings = ("Carrier", "Actual", "Estimated", "Load Count")
return render_template('/page.html', headings=headings, data=data)