gpt4 book ai didi

Python Pylons/Pyramid cookies

转载 作者:太空宇宙 更新时间:2023-11-04 04:40:08 26 4
gpt4 key购买 nike

在 Pylons/Pyramid 中设置和获取 cookie 的最佳方式是什么?

Response.set_cookie('example_cookie_name', 'example', max_age=180*24*3600)

返回错误

  File "/usr/local/lib/python3.5/dist-packages/webob/response.py", line 1071, in set_cookie
self.headerlist.append(('Set-Cookie', cookie))
AttributeError: 'str' object has no attribute 'headerlist'

最佳答案

你似乎在做这样的事情:

from pyramid.response import Response
Response.set_cookie('example_cookie_name', 'example', max_age=180*24*3600)

问题是 Response 是一个类,您调用它的未绑定(bind)方法 set_cookie 传递一个字符串代替 self 参数.

(有趣的事实 - 在 Python 2 中错误是 much clearer )

您需要实例化一个新的响应对象或简单地使用 request.response 属性。

关于Python Pylons/Pyramid cookies ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50843264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com