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

2024/9/22 7:20:58

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_appresponse = self.full_dispatch_request()File "flask/app.py", line 1834, in full_dispatch_requestrv = self.handle_user_exception(e)File "flask/app.py", line 1737, in handle_user_exceptionreraise(exc_type, exc_value, tb)File "flask/_compat.py", line 36, in reraiseraise valueFile "flask/app.py", line 1832, in full_dispatch_requestrv = self.dispatch_request()File "flask/app.py", line 1818, in dispatch_requestreturn self.view_functions[rule.endpoint](**req.view_args)File "/home/mlesage/mysite/Court/application.py", line 40, in homecomplaints = db.execute("SELECT User_Complaint, Date, Review_Title FROM Posts")File "cs50/sql.py", line 224, in executeraise 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 METHODelse: 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.

Answer

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://en.xdnf.cn/q/119083.html

Related Q&A

Installing Scipy for Windows

I am trying to install Scipy on my computer. I did it by using the command pip install Scipy. (pip & numpy are up-to-date and I am using Python 3.6) I also tried it with Pycharm, but it didnt worke…

Python Opencv, dont put circle on the video

I wrote the following script with OpenCVimport cv2 import numpy as npcap = cv2.VideoCapture(0) ix, iy = -1, -1def draw_circle(event, x, y, flags, param):global ixglobal iyix,iy = x,yif event == cv2.EVE…

List coordinates between a set of coordinates

This should be fairly easy, but Im getting a headache from trying to figure it out. I want to list all the coordinates between two points. Like so:1: (1,1) 2: (1,3) In between: (1,2)Or1: (1,1) 2: (5,1)…

NA values in column is not NaN Pandas Python [duplicate]

This question already has answers here:Prevent pandas from interpreting NA as NaN in a string(7 answers)Closed 2 years ago.I got a CSV File. I got a column Product. One of the products in it, called NA…

How to fix pandas column data

Workflow is :Read CSV file using Pythons pandas library and get Variation Column Variation Column data isVariation ---------- Color Family : Black, Size:Int:L Color Family : Blue, Size:Int:M Color Fam…

Connect to Oracle Database and export data as CSV using Python

I want to connect oracle database to python and using select statement whatever result i will get, I want that result to be exported as csv file in sftp location. I know we can connect oracle with pyth…

Pandas data frame: convert Int column into binary in python

I have dataframe eg. like below Event[EVENT_ID] = [ 4162, 4161, 4160, 4159,4158, 4157, 4156, 4155, 4154]need to convert each row word to binary. Event[b]=bin(Event[EVENT_ID]) doesnt work TypeError: can…

I have an issue : Reading Multiple Text files using Multi-Threading by python

Hello Friends, I hope someone check my code and helping me on this issue. I want to read from multiple text files (at least 4) sequentially and print their content on the screenFirst time not using Thr…

How to print \ in python?

print "\\"It print me in console...But I want to get string \How to get string string \?

Replace word, but another word with same letter format got replaced

Im trying to replace a word in python, but another word with same letter format got replaced example : initial : bg bgt goal : bang banget current result : bang bangtheres what my code…