【问题标题】:Why I am getting TypeError on production server where I am trying to save data in the session?为什么我在尝试在会话中保存数据的生产服务器上收到 TypeError?
【发布时间】:2013-09-07 04:15:30
【问题描述】:

环境:

Request Method: GET
Request URL: django_server_running_on_apache

Django Version: 1.3.3
Python Version: 2.7.3

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  178.                 response = middleware_method(request, response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/middleware.py" in process_response
  36.                 request.session.save()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/file.py" in save
  121.                     os.write(output_file_fd, self.encode(session_data))
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/base.py" in encode
  93.         pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)

Exception Type: TypeError at /
Exception Value: expected string or Unicode object, NoneType found

【问题讨论】:

  • TypeError 说:预期的字符串或 Unicode 对象,NoneType 找到。所以这就是原因。如需更多帮助,您需要显示引发错误的代码。

标签: python django apache pickle django-sessions


【解决方案1】:

建议在会话中只存储标量对象。 Pickel 无法序列化其他对象。

【讨论】:

    猜你喜欢
    • 2019-01-18
    • 2011-11-03
    • 1970-01-01
    • 2013-01-05
    • 2011-06-11
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多