【问题标题】:Self.request.cookies.get is not returning complete value of the cookie in google app engineSelf.request.cookies.get 没有返回谷歌应用引擎中 cookie 的完整值
【发布时间】:2017-03-13 04:33:59
【问题描述】:

我将 cookie 值设置为 (id, hash_of_id),但是当代码读取 cookie 的值时,它只获取逗号之前的部分。不知道为什么:

这些是代码:

这是设置名为 user_id 的 cookie 的值。

self.response.headers.add_header('Set-Cookie', 'user_id = %s; Path=/' % id_hash)

id_hash 的值来自以下:

def make_hash(user_id): return hmac.new(SECRET, str(user_id)).hexdigest()

def new_hash(user_id): id_hash = make_hash(user_id) return "%s,%s" %((user_id), id_hash)

id_hash = new_hash(user.key().id())

当我使用编辑此 Cookie 扩展程序检查浏览器中 cookie 的值时,它会显示如下内容:

This shows cookie has got id and hashed value of id.

现在正在读取 cookie 的值:

cookiess = self.request.cookies.get('user_id')

当我使用显示变量 cookie 的值时

self.render("welcome.html", username = cookiess)

只显示逗号前的部分,

enter image description here

我无法理解为什么 self.request.cookie.get 只在逗号之前返回值而不是完整值。

【问题讨论】:

    标签: cookies google-app-engine-python


    【解决方案1】:

    得知谷歌应用引擎中存在一个错误

    self.request.cookie.get()

    直到逗号才返回值。如果使用管道 (|) 之类的其他东西作为分隔符,而不是逗号,则此功能正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      • 2011-09-18
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      相关资源
      最近更新 更多