开发者

appengine python Set-Cookie problem

below code is working as it should in the server...while coming to localhost cookie not setting please help me to fix this..

def set_cookie(self, key, value='', max_age=None,
                   path='/', d开发者_运维问答omain=None, secure=None, httponly=False,
                   version=None, comment=None):
        """
        Set (add) a cookie for the response
        """       
    cookies = BaseCookie()
        cookies[key] = value
        for var_name, var_value in [
            ('max-age', max_age),
            ('path', path),
            ('domain', domain),
            ('secure', secure),
            ('HttpOnly', httponly),
            ('version', version),
            ('comment', comment),
            ]:
            if var_value is not None and var_value is not False:
                cookies[key][var_name] = str(var_value)
            if max_age is not None:
                cookies[key]['expires'] = max_age
        header_value = cookies[key].output(header='').lstrip()
        self.response.headers._headers.append(('Set-Cookie', header_value))


Try to use

self.response.headers.add_header("Set-Cookie", header_value)

instead of

self.response.headers._headers.append(('Set-Cookie', header_value))

Also try Cookie.SimpleCookie() instead of Cookie.BaseCookie()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜