Django 会话奇怪行为:十进制文字无效:'2011-01-04 09:36:59'错误

发布于 2024-10-08 20:07:01 字数 3185 浏览 2 评论 0原文

我在尝试从网络应用程序上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多像笑话 2024-10-15 20:07:01

看起来是一个非常晦涩难懂的问题。我能找到的只有这个线程:
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 decimal

If nobody answers I'd reach out to the guy in the link above because it's literally the single mention on the internets.

栖迟 2024-10-15 20:07:01

看来问题与在同一个 apache 实例中运行的 php 和 python 有关,

当我评论 httpd.conf 中的行时

LoadModule php5_module                    /usr/lib/apache2/mod_php5.so

,它开始正常工作。

It seems that the problem is related to php and python running in the same apache instance,

When I commented the line

LoadModule php5_module                    /usr/lib/apache2/mod_php5.so

in httpd.conf, it started working normally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文