问题
The list in the left column of ontariocourts311.ca, along with the body of the page under the image intermittently fail to display (which is 'fixed' by refreshing the page). I'm a Noob, and have tried various versions of the return statement without success.
Error:
2019-06-05 16:39:26,765: Exception on / [GET]
Traceback (most recent call last):
File "flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "flask/_compat.py", line 36, in reraise
raise value
File "flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/mlesage/mysite/Court/application.py", line 40, in home
complaints = db.execute("SELECT User_Complaint, Date, Review_Title FROM Posts")
File "cs50/sql.py", line 224, in execute
raise e
RuntimeError: (MySQLdb._exceptions.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: SELECT User_Complaint, Date, Review_Title FROM Posts]
(Background on this error at: http://sqlalche.me/e/e3q8)
from cs50 import SQL
from helpers import contacts # (a list of people stored in helpers)
# Configure db to mySQL database
db = SQL("mysql://user.mysql.pythonanywhere-services.com:3306/user$User_Reviews")
#timeout = db.execute(con.query('SET GLOBAL connect_timeout=6000'))
@app.route("/", methods=["GET", "POST"])
def home():
reviews = [list of reviews, pulled from db, for display on page]
if request.method == "POST":
if User_Complaint != None:
return redirect ('/')
#return redirect(url_for('home', reviews = reviews, contacts = contacts))
else:
return render_template("home.html", reviews = reviews, contacts = contacts)
# GETS METHOD
else:
return render_template("home.html", reviews = reviews, contacts = contacts)
Page elements should display consistently (i.e. left side list of people, reviews in center of page and text box), whether using GETS or POST method.
回答1:
It looks like the problem had to do with MySQL not having available open connections, which appears to have been fixed via the slight modification to the following line:
db = SQL("mysql://user:password.mysql.pythonanywhere-services.com:3306/user$User_Reviews", pool_recycle = 280)
来源:https://stackoverflow.com/questions/56466829/how-do-i-fix-this-gets-server-error-which-is-causing-display-issues