I have a Django application running on the Google App Engine. From time to time, the DB raises an OperationalError
, which is normal, however my code, although using try..except, does not catch the exception (I need this for retries).
Here is my code:
from MySQLdb import OperationalError, DatabaseError DB_RETRY_EXCEPTIONS = ( OperationalError, DatabaseError, ) class MyClassView(rest_framework.views.APIView): @retry(DB_RETRY_EXCEPTIONS, tries=5, delay=5, logger=logger) def dispatch(self, *args, **kwargs): try: return super(MyClassView, self).dispatch(*args, **kwargs) except DB_RETRY_EXCEPTIONS as exp: logger.warning("Got %s", exp) raise
In the exception stack trace, I see that the thread goes through this piece of code, but no warnings.
Here are the last lines of the stack trace:
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/connections.py", line 190, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 38")
Any help is appreciated.