我已经完全部署了django应用程序(debug=true),当我以某种方式查询数据库时,常常会丢失mysql连接并出现以下错误: Exception Value: (2013, 'Lost connection to MySQL server during query')
. 这似乎是随机发生的。我可以进行5-8次查询,然后得到错误。发生这种情况的原因是什么?谢谢。
以下是完整的回溯:
Environment:
Request Method: GET
Request URL: https://www.tcgfirst.com/
Django Version: 2.0
Python Version: 3.6.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'engine',
'contact',
'crispy_forms',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'stripe',
'checkout']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in _get_session
191. return self._session_cache
During handling of the above exception ('SessionStore' object has no attribute '_session_cache'), another exception occurred:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in execute
71. return self.cursor.execute(query, args)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in execute
250. self.errorhandler(self, exc, value)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in defaulterrorhandler
50. raise errorvalue
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in execute
247. res = self._query(query)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in _query
411. rowcount = self._do_query(q)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in _do_query
374. db.query(q)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in query
277. _mysql.connection.query(self, query)
The above exception ((2013, 'Lost connection to MySQL server during query')) was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args,**callback_kwargs)
File "/app/engine/views.py" in home
23. cart = Cart(request)
File "/app/engine/cart.py" in __init__
35. cart = self.session.get(settings.CART_SESSION_KEY)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in get
66. return self._session.get(key, default)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in _get_session
196. self._session_cache = self.load()
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in load
34. expire_date__gt=timezone.now()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method
82. return getattr(self.get_queryset(), name)(*args,**kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in get
397. num = len(clone)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __len__
254. self._fetch_all()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
1179. self._result_cache = list(self._iterable_class(self))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1063. cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
100. return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
68. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
77. return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in execute
71. return self.cursor.execute(query, args)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in execute
250. self.errorhandler(self, exc, value)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in defaulterrorhandler
50. raise errorvalue
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in execute
247. res = self._query(query)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in _query
411. rowcount = self._do_query(q)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/cursors.py" in _do_query
374. db.query(q)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in query
277. _mysql.connection.query(self, query)
Exception Type: OperationalError at /
Exception Value: (2013, 'Lost connection to MySQL server during query')
暂无答案!
目前还没有任何答案,快来回答吧!