Skip to content

Commit

Permalink
feat: add cookies from http session to ws (#3312)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Gerrits <[email protected]>
  • Loading branch information
timrbula and jackgerrits authored Sep 25, 2024
1 parent ddc2eaa commit 3d6a770
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion autogen/coding/jupyter/jupyter_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def _get_headers(self) -> Dict[str, str]:
return {}
return {"Authorization": f"token {self._connection_info.token}"}

def _get_cookies(self) -> str:
cookies = self._session.cookies.get_dict()
return "; ".join([f"{name}={value}" for name, value in cookies.items()])

def _get_api_base_url(self) -> str:
protocol = "https" if self._connection_info.use_https else "http"
port = f":{self._connection_info.port}" if self._connection_info.port else ""
Expand Down Expand Up @@ -87,7 +91,7 @@ def restart_kernel(self, kernel_id: str) -> None:

def get_kernel_client(self, kernel_id: str) -> JupyterKernelClient:
ws_url = f"{self._get_ws_base_url()}/api/kernels/{kernel_id}/channels"
ws = websocket.create_connection(ws_url, header=self._get_headers())
ws = websocket.create_connection(ws_url, header=self._get_headers(), cookie=self._get_cookies())
return JupyterKernelClient(ws)


Expand Down

0 comments on commit 3d6a770

Please sign in to comment.