diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 8aa3dbd08..e65665f59 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -2377,7 +2377,8 @@ def local_url(self) -> str: parts = self._get_urlparts(include_token=True) # Update with custom pieces. if not self.sock: - parts = parts._replace(netloc=f"127.0.0.1:{self.port}") + localhost = "[::1]" if ":" in self.ip else "127.0.0.1" + parts = parts._replace(netloc=f"{localhost}:{self.port}") return parts.geturl() @property