如何解决此Gets服务器错误,这会导致显示问题? [英] How do I fix this Gets server error, which is causing display issues?

查看:56
本文介绍了如何解决此Gets服务器错误,这会导致显示问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ontariocourts311.ca左列中的列表以及图像下方的页面正文间歇性地无法显示(通过刷新页面来固定").我是Noob,并且尝试过各种版本的return语句,但均未成功.

错误:

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)   

无论使用GETS还是POST方法,页面元素都应保持一致显示(即,左侧的人员名单,页面中央和文本框的评论).

解决方案

问题似乎与MySQL没有可用的开放连接有关,该开放连接似乎已通过对以下行稍加修改而得以解决:

db = SQL("mysql://user:password.mysql.pythonanywhere-services.com:3306/user $ User_Reviews",pool_recycle = 280)

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.

解决方案

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)

这篇关于如何解决此Gets服务器错误,这会导致显示问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆