Django 会话奇怪行为:十进制文字无效:'2011-01-04 09:36:59'错误
我在尝试从网络应用程序上的 django_session 表中检索会话内容时遇到此错误。我正在使用 request.session.get('mykey_name') django 执行的查询是:
s = Session.objects.get(session_key = self.session_key,expire_date__gt=datetime.datetime.now()
kwargs 是: {'expire_date__gt': datetime. datetime(2010, 12, 21, 14, 27, 6, 138883), 'session_key': '721c947a60432c3ac3bbdd485931c945'}
这是完整的回溯:
Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
80. response = middleware_method(request)
File "/usr/local/lib/python2.7/site-packages/pyfacegraph-0.0.4-py2.7.egg/facegraph/django/middleware.py" in process_request
46. request.graph = self.graph_for_request(request)
File "/usr/local/lib/python2.7/site-packages/pyfacegraph-0.0.4-py2.7.egg/facegraph/django/middleware.py" in graph_for_request
51. access_token = self.access_token(request)
File "/home/roohitne/djangoCode/roohit/fb/middleware.py" in access_token
7. return request.session.get('access_token')
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in get
63. return self._session.get(key, default)
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
172. self._session_cache = self.load()
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load
20. expire_date__gt=datetime.datetime.now()
File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in get
336. num = len(clone)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
81. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
269. for row in compiler.results_iter():
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
672. for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
727. cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
15. return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
86. return self.cursor.execute(query, args)
File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.2-py2.7-linux-i686.egg/MySQLdb/cursors.py" in execute
166. self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.2-py2.7-linux-i686.egg/MySQLdb/connections.py" in defaulterrorhandler
35. raise errorclass, errorvalue
Exception Type: InvalidOperation at /oauth/callback/
Exception Value: Invalid literal for Decimal: '2011-01-04 14:04:39'
我使用 django 1.2.3 和 python 2.7,数据库版本是 5.1.33 -CentOS 下的社区。 任何猜测为什么会发生这种情况? 提前致谢!
i'm getting this error while trying to retrieve a session content from the django_session table on my web app. I'm using request.session.get('mykey_name')
The query django performs to get this is:
s = Session.objects.get(session_key = self.session_key,expire_date__gt=datetime.datetime.now()
The kwargs are: {'expire_date__gt': datetime.datetime(2010, 12, 21, 14, 27, 6, 138883), 'session_key': '721c947a60432c3ac3bbdd485931c945'}
Here is the full traceback:
Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
80. response = middleware_method(request)
File "/usr/local/lib/python2.7/site-packages/pyfacegraph-0.0.4-py2.7.egg/facegraph/django/middleware.py" in process_request
46. request.graph = self.graph_for_request(request)
File "/usr/local/lib/python2.7/site-packages/pyfacegraph-0.0.4-py2.7.egg/facegraph/django/middleware.py" in graph_for_request
51. access_token = self.access_token(request)
File "/home/roohitne/djangoCode/roohit/fb/middleware.py" in access_token
7. return request.session.get('access_token')
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in get
63. return self._session.get(key, default)
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
172. self._session_cache = self.load()
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load
20. expire_date__gt=datetime.datetime.now()
File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in get
336. num = len(clone)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
81. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
269. for row in compiler.results_iter():
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
672. for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
727. cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
15. return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
86. return self.cursor.execute(query, args)
File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.2-py2.7-linux-i686.egg/MySQLdb/cursors.py" in execute
166. self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.2-py2.7-linux-i686.egg/MySQLdb/connections.py" in defaulterrorhandler
35. raise errorclass, errorvalue
Exception Type: InvalidOperation at /oauth/callback/
Exception Value: Invalid literal for Decimal: '2011-01-04 14:04:39'
I'm usig django 1.2.3 and python 2.7 and the database version is 5.1.33-community under CentOS.
Any guesses why is this happening?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来是一个非常晦涩难懂的问题。我能找到的只有这个线程:
http://groups.google.com/group/django-users/browse_thread /thread/2e04a75e5da3c278
您最近是否升级或迁移了数据库?该问题在新的
syncdb
数据库中是否仍然存在?可能想排除这一点。由于当您未提供该信息时错误会返回
2011-01-04 14:04:39
,因此某些内容已成功写入数据库并从中读取,但其他内容正在将其转换为十进制...不幸的是我不知道django或mysqldb如何/何时尝试将日期时间转换为十进制如果没有人回答我会联系上面链接中的人,因为它实际上是互联网上的单一提及。
Seems like a very obscure problem. All I can find on it is this thread:
http://groups.google.com/group/django-users/browse_thread/thread/2e04a75e5da3c278
Did you upgrade or migrate the DB recently? Is the problem persistent in a newly
syncdb
database? Might want to rule that one out.Since the error returns
2011-01-04 14:04:39
when you haven't supplied that information, something is successfully writing to the DB and reading from it but something else is converting it to a decimal... Unfortunately I don't know how / when django or mysqldb tries to convert datetime to a decimalIf nobody answers I'd reach out to the guy in the link above because it's literally the single mention on the internets.
看来问题与在同一个 apache 实例中运行的 php 和 python 有关,
当我评论 httpd.conf 中的行时
,它开始正常工作。
It seems that the problem is related to php and python running in the same apache instance,
When I commented the line
in httpd.conf, it started working normally.