Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

python - How do I fix this Gets server error, which is causing display issues?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...