Hi all,
I've been struggling with a MySQL server getting the (2006, 'MySQL server has gone away') error.
Just to give a little background I'm a self-taught "hobby" programmer. I want to put all my learning to the test so I'm building a Kivy app that marks bathrooms near you. I'm running a Kivy app that uses Mapview to generate a map and place markers on itself. When the Map is being initialized it uses Python 'requests' to call to the Bottle web app which makes and returns a database query. (This is my first time doing this so I'm sure I'm missing something obvious or doing something inefficient)
So the first time I run the app it works fine. The Kivy app makes a request to the Bottle app, I use ".json()" on the return and read lat/lon coordinates out of.to place a marker on the Map.... BUT if I wait a little while, close the app, and try to do it again (or just access the website normally) I get a "500 internal server error". When I check the error log it shows (2006, 'MySQL server has gone away').
I only have 1 row in 1 table in MySQL database so I'm assuming it isn't a size issue. I'm assuming there is some way I'm not closing the connection (although I tried to put in fail safes for this).
The relevant code snippet from my Kivy app and my entire Bottle app are shown below. Any help is appreciated and I'll check frequently to provide any additional information if needed. Thanks!
REQUEST FUNCTION FROM KIVY (snippet):
def find_me():
with requests.Session() as s:
query_dict = s.get('http://MY URL').json()
my_info = (query_dict['1']['name'], query_dict['1']['description'], query_dict['1']['lon'], query_dict['1']['lat'])
return my_info
BOTTLE APP CONTAINING THE QUERY:
from bottle import default_app, route, hook
from peewee import *
from babybottom import BoyBathroom
db = MySQLDatabase(*ALL DATABSE INFO ENTERED CORRECTLY HERE*)
@hook('before_request')
def _connect_db():
db.connect()
@hook('after_request')
def _close_db():
if not db.is_closed():
db.close()
@route('/')
def hello_world():
test = BoyBathroom.select().where(BoyBathroom.name == 'Nick House').get()
info_dict = {test.id:{'name':test.name, 'description':test.description,'lon':test.lon, 'lat':test.lat}}
return info_dict
application = default_app()