Reputation: 39
I am setting the cookie value to (id, hash_of_id), but when the code is reading the value of the cookie it is getting only the part before comma. Not sure why:
These are the codes:
This is setting the values of the cookie named user_id.
self.response.headers.add_header('Set-Cookie', 'user_id = %s; Path=/' % id_hash)
The value of id_hash is coming from following:
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())
When I am checking the value of the cookie in the browser using Edit this Cookie extension, it shows something like this:
This shows cookie has got id and hashed value of id.
Now value of cookie is being read:
cookiess = self.request.cookies.get('user_id')
When I am displaying the value of variable cookiess using
self.render("welcome.html", username = cookiess)
It shows only the part before comma,
I am not able to understand why the self.request.cookie.get returns value only till comma and not complete value.
Upvotes: 0
Views: 629
Reputation: 39
Came to know that there is a bug in google appengine due to which
self.request.cookie.get()
was returning value only till comma. Instead of comma if something else like a pipe (|) is used as separator, then this function is working properly.
Upvotes: 1