Hi
I am using Django3.0.1, and AWS RDS for the mysql database.
I am now facing error “mysql server has gone away” quite often.
Here are error traceback.
Could someone help me please?
Traceback (most recent call last):
File “/usr/local/lib/python3.8/dist-packages/django/contrib/sessions/backends/base.py”, line 199, in _get_session
return self._session_cache
AttributeError: ‘SessionStore’ object has no attribute ‘_session_cache’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 16, in wrapper
return f(self, query, args)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 45, in execute
return self.cursor.execute(query, args)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 206, in execute
res = self._query(query)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 319, in _query
db.query(q)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py”, line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (2006, ‘MySQL server has gone away’)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “./XPertDirect/module/xd/decorators/permission.py”, line 13, in decorated_function
if args[0].user.is_authenticated:
File “/usr/local/lib/python3.8/dist-packages/django/utils/functional.py”, line 224, in inner
self._setup()
File “/usr/local/lib/python3.8/dist-packages/django/utils/functional.py”, line 360, in _setup
self._wrapped = self._setupfunc()
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/middleware.py”, line 24, in
request.user = SimpleLazyObject(lambda: get_user(request))
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/middleware.py”, line 12, in get_user
request._cached_user = auth.get_user(request)
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/init.py”, line 173, in get_user
user_id = _get_user_session_key(request)
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/init.py”, line 58, in _get_user_session_key
return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File “/usr/local/lib/python3.8/dist-packages/django/contrib/sessions/backends/base.py”, line 64, in getitem
return self._session[key]
File “/usr/local/lib/python3.8/dist-packages/django/contrib/sessions/backends/base.py”, line 204, in _get_session
self._session_cache = self.load()
File “/usr/local/lib/python3.8/dist-packages/django/contrib/sessions/backends/db.py”, line 43, in load
s = self._get_session_from_db()
File “/usr/local/lib/python3.8/dist-packages/django/contrib/sessions/backends/db.py”, line 32, in _get_session_from_db
return self.model.objects.get(
File “/usr/local/lib/python3.8/dist-packages/django/db/models/manager.py”, line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 411, in get
num = len(clone)
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 258, in len
self._fetch_all()
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 57, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File “/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py”, line 1144, in execute_sql
cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 16, in wrapper
return f(self, query, args)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 45, in execute
return self.cursor.execute(query, args)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 206, in execute
res = self._query(query)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 319, in _query
db.query(q)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py”, line 259, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (2006, ‘MySQL server has gone away’)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 16, in wrapper
return f(self, query, args)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 45, in execute
return self.cursor.execute(query, args)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 206, in execute
res = self._query(query)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 319, in _query
db.query(q)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py”, line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (2006, ‘MySQL server has gone away’)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py”, line 34, in inner
response = get_response(request)
File “/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py”, line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File “/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py”, line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “./XPertDirect/module/xd/decorators/permission.py”, line 18, in decorated_function
return func(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/django/views/generic/base.py”, line 71, in view
return self.dispatch(request, *args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/django/views/generic/base.py”, line 97, in dispatch
return handler(request, *args, **kwargs)
File “./XPertDirect/section/home/view/LoginView.py”, line 11, in post
user = authenticate(
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/init.py”, line 72, in authenticate
user = backend.authenticate(request, credentials)
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/backends.py”, line 46, in authenticate
user = UserModel._default_manager.get_by_natural_key(username)
File “/usr/local/lib/python3.8/dist-packages/django/contrib/auth/base_user.py”, line 44, in get_by_natural_key
return self.get({self.model.USERNAME_FIELD: username})
File “/usr/local/lib/python3.8/dist-packages/django/db/models/manager.py”, line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 411, in get
num = len(clone)
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 258, in len
self._fetch_all()
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File “/usr/local/lib/python3.8/dist-packages/django/db/models/query.py”, line 57, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File “/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py”, line 1144, in execute_sql
cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 16, in wrapper
return f(self, query, args)
File “/usr/local/lib/python3.8/dist-packages/mysql_server_has_gone_away/base.py”, line 45, in execute
return self.cursor.execute(query, args)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 206, in execute
res = self._query(query)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py”, line 319, in _query
db.query(q)
File “/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py”, line 259, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (2006, ‘MySQL server has gone away’)