Forums

sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2006, 'MySQL server has gone away')

I've already tried:

  • https://help.pythonanywhere.com/pages/ManagingDatabaseConnections
  • https://www.pythonanywhere.com/forums/topic/3658/
  • https://www.pythonanywhere.com/forums/topic/7369/

But I keep getting the error, here's an example of what causes the error:

mysite/app/db.py

import dataset
from config import DATABASE_URL

# Database setup
print('DATABASE', DATABASE_URL)

if 'mysql' in DATABASE_URL:
        database = dataset.connect(
            DATABASE_URL,
            engine_kwargs={
                "pool_recycle": 280,
                "pool_timeout": 20,
            },
        )
else:
    database = dataset.connect(DATABASE_URL)

users = database['users']
customers = database['customers']
comments = database['comments']

mysite/app/init.py

@app.get('/app/user/<uid>')
@auth.authenticated
def get_user(uid):
   """Show user view"""
    user = users.find_one(uid=uid)
    form = EditUserForm()

    return template(
        'user.html',
        user=user,
        form=form,
        message=request.message,
    )

For reference, I'm using dataset as my ORM and the Bottle framework.

Hmm, OK. So the "pool_recycle": 280, that you're setting should be enough to fix the problem. Just a quick sanity-check -- is that something you added recently? And did you reload the site from the "Web" tab after adding it?