Weird Behaviour For Python Cookies, Unable To Set Cookies
I am using Python Nameko as my microservice framework, and when I try to set cookies in my get request, I can't seems to do it, below is my code:
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!'
Anyone can help in understanding the behaviour? Instead of Set-Cookie ->, it's ->, as shown in the image. Thank you.
As per the docs, the 3-tuple response type for
(status_code, headers dict, response body). That is, the second argument is a dict of headers, which is not the same as a cookie object
To set cookies you need to construct an instance of
werkzeug.wrappers.Response yourself (also included in that list in the docs):
@http('GET', '/hello') def say_hello(self, request): response = Response("Hello World!") response.set_cookie('test-cookie', 'test-1') return response
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module