L
L
Leo2015-06-10 17:29:53
Python
Leo, 2015-06-10 17:29:53

Why can't Tornado Websockets see cookies?

Cookies are immediately sent to the client on the main page:

class IndexHandler(RequestHandler):
  def get(self):
    if not self.get_secure_cookie("user"):
      self.set_secure_cookie("user", "1213", domain='127.0.0.1')
    self.render("index.html",)

In index.html there is a js code that is responsible for connecting to the host:
var ws = new WebSocket("ws://localhost:8888/websocket");
// и т.д

Everything works great (messages are sent and delivered), cookies are visible in the browser, but there is a problem - Tornado for some reason does not see cookies:
class HiHandler(WebSocketHandler):
  def open(self):
    print("WebSocket opened")
    print("received cookies: ", self.request.cookies)
    print("received 'myuser': ", self.get_secure_cookie("user"))

The output is:
WebSocket opened
received cookies:  
received 'myuser':  None

Why is this happening and how to fix it?
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question