通过 python websocket 客户端传递 cookie

Passing cookie through python websocket client

我正在使用 websocket-client 连接到 node.js 服务器(这是我的 websocket 服务器),我已经能够通过 websockets 从 python 发送消息到 node.js成功。

我的 python 客户端使用 requests module to login to a website and collect the cookies (that are passed from the server as a result of successful login). I would like these cookies to be passed as a part of websocket-client as shown in the code here

我从登录中获得以下 cookie:

(Pdb) requests.utils.dict_from_cookiejar(client.cookies)
{'csrftoken': 'DhSf0z9Ouu5f1SbfGWBg5BuBe1UuJMLr', 'sessionid': 'pu6ig4z4mtq5k8rvm6kuv8g3fdegs47d'}

创建 websocket 时如何发送该 cookie?

ws = websocket.WebSocketApp("ws://localhost:8080/",
                          on_message = on_message,
                          on_error = on_error,
                          on_close = on_close,
                          # cookie = ? what goes here ?
    )

就是这样:

ws = websocket.WebSocketApp("ws://localhost:8080/",
                          on_message = on_message,
                          on_error = on_error,
                          on_close = on_close,
                          cookie = "csrftoken=DhSf0z9Ouu5f1SbfGWBg5BuBe1UuJMLr; sessionid=pu6ig4z4mtq5k8rvm6kuv8g3fdegs47d"
)

它的意思是传递一个简单的字符串