python Cookie行为怪异,无法设置Cookie

python Cookie行为怪异,无法设置Cookie,python,cookies,http-headers,setcookie,nameko,Python,Cookies,Http Headers,Setcookie,Nameko,我使用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'] = '

我使用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请求时,下面是我从请求中得到的信息:

有人能帮助理解这种行为吗? 它不是设置Cookie->,而是->,如图所示。 谢谢。

根据,nameko.http的三元组响应类型是status_code、headers dict、response body。也就是说,第二个参数是头的dict,它与cookie对象不同

要设置cookie,您需要构建一个您自己的实例,该实例也包含在文档中的列表中:

    @http('GET', '/hello')
    def say_hello(self, request):
        response = Response("Hello World!")
        response.set_cookie('test-cookie', 'test-1')
        return response

谢谢你的回答@second,我尝试使用你建议的包装器,但我只得到:Error:TypeError:Payload必须是字符串。当我将包装器与.set_cookie函数一起使用时,没有得到任何结果。听起来它可能是您正在执行的特定操作。可能会发布一个新问题,其中包含一个可运行但最少的代码示例,该示例显示了问题hi second,当我执行response=ResponseHello World时,一切都很好!,200,然后是set cookie。感觉像是虫子什么的