Self.request.cookies.get 未在 google 应用引擎中返回 cookie 的完整值
Self.request.cookies.get is not returning complete value of the cookie in google app engine
我将 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')
当我使用
显示变量 cookies 的值时
self.render("welcome.html", username = cookiess)
只显示逗号前的部分,
enter image description here
我无法理解为什么 self.request.cookie.get returns 值只有逗号而不是完整值。
了解到 google appengine 中存在一个错误
self.request.cookie.get()
只在逗号之前返回值。如果使用管道 (|) 之类的其他东西作为分隔符而不是逗号,则此功能可以正常工作。
我将 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')
当我使用
显示变量 cookies 的值时self.render("welcome.html", username = cookiess)
只显示逗号前的部分,
enter image description here
我无法理解为什么 self.request.cookie.get returns 值只有逗号而不是完整值。
了解到 google appengine 中存在一个错误
self.request.cookie.get()
只在逗号之前返回值。如果使用管道 (|) 之类的其他东西作为分隔符而不是逗号,则此功能可以正常工作。