我使用Python Nameko作为我的微服务框架,当我尝试在get请求中设置cookie时,我似乎做不到,下面是我的代码:
from http import cookies
from nameko.web.handlers import http
@http('GET', '/hello')
def say_hello(self, request):
c = cookies.SimpleCookie()
c['test-cookie'] = 'test-1'
return 200, c, 'Hello World!'
当我使用Postman调用get请求时,下面是我从请求中得到的结果:
有人能帮助理解这种行为吗? 它不是Set Cookie->;,而是->;,如图所示。 非常感谢。你知道吗
根据the docs,
nameko.http
的三元组响应类型是(status_code, headers dict, response body)
。也就是说,第二个参数是头的dict,它与cookie对象不同要设置cookie,您需要自己构造一个^{} 实例(也包括在文档的列表中):
相关问题 更多 >
编程相关推荐