CookieError:非法键值

时间:2012-08-23 02:32:24

标签: python google-app-engine cookies

Dump Error:

Traceback (most recent call last):
  File "/base/data/home/apps/s~tagtoo-ec/1.361220954515344675/libs/handlers.py", line 69, in get
    self.beforeFilter()
  File "/base/data/home/apps/s~tagtoo-ec/1.361220954515344675/libs/handlers.py", line 51, in beforeFilter
    self.set_track()
  File "/base/data/home/apps/s~tagtoo-ec/1.361220954515344675/libs/handlers.py", line 99, in set_track
    track_id = self.request.cookies.get("tagtoo_user_track", None)
  File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 985, in cookies
    vars = self.str_cookies
  File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 973, in str_cookies
    cookies.load(source)
  File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 619, in load
    self.__ParseString(rawdata)
  File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 650, in __ParseString
    self.__set(K, rval, cval)
  File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 572, in __set
    M.set(key, real_value, coded_value)
  File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 451, in set
    raise CookieError("Illegal key value: %s" % key)
CookieError: Illegal key value: tagtoo_u{er_track

我多次收到此错误消息。

问题是

  1. 我使用的键值是“tagtoo_user_track”。 “tagtoo_u {er_track”来自哪里?
  2. 此错误并非总是发生。我在每个请求中都使用了相同的方法。如果完全错误,则应在每个请求中引发此异常。但是,错误消息只会提高几次。
  3. 这是谷歌应用引擎的错误吗?

    EDIT1

    又发生了另一个cookie密钥“tagtoo_user_track”。 看起来cookie引擎不喜欢“s”。

    Traceback (most recent call last):
      File "/base/data/home/apps/s~tagtoo-ec/1.361220954515344675/libs/handlers.py", line 69, in get
        self.beforeFilter()
      File "/base/data/home/apps/s~tagtoo-ec/1.361220954515344675/libs/handlers.py", line 51, in beforeFilter
        self.set_track()
      File "/base/data/home/apps/s~tagtoo-ec/1.361220954515344675/libs/handlers.py", line 99, in set_track
        track_id = self.request.cookies.get("tagtoo_user_track", None)
      File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 985, in cookies
        vars = self.str_cookies
      File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 973, in str_cookies
        cookies.load(source)
      File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 619, in load
        self.__ParseString(rawdata)
      File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 650, in __ParseString
        self.__set(K, rval, cval)
      File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 572, in __set
        M.set(key, real_value, coded_value)
      File "/base/python_runtime/python_dist/lib/python2.5/Cookie.py", line 451, in set
        raise CookieError("Illegal key value: %s" % key)
    CookieError: Illegal key value: tagtoo_user_ses{ion
    

1 个答案:

答案 0 :(得分:0)

看起来像cookie字符串中存在格式错误。 只要用户使用相关的cookie值,python 2.5 cookies lib就会引发异常。

可以通过检测错误的cookie值 self.request.environ.get("HTTP_COOKIE")

因此,我会在提出异常时手动解析cookie以避免此问题。