Using tabs does not respect port, and opens new browser tabs on even other ports?

Hello,

Let me pro-actively thank anyone that looks into this. I really appreciate it.

If I run the following code:

import panel as pn

pn.extension()

# Create content for Tab 1
tab1_content = pn.Column(
    pn.pane.Markdown("# Tab 1"), pn.widgets.TextInput(name="Enter text for Tab 1")
)

# Create content for Tab 2
tab2_content = pn.Column(
    pn.pane.Markdown("# Tab 2"),
)

# Create the tabbed interface
tabs = pn.Tabs(("Tab 1", tab1_content), ("Tab 2", tab2_content))

# Serve the application
pn.serve(tabs)

With the command [1]:

panel serve tabs_example.py --port 9001 --basic-auth test --cookie-secret test

I expect to go to http://localhost:9001/tabs_example
The output I get in the shell, confirms that:

2024-07-26 19:23:28,641 Starting Bokeh server version 3.4.2 (running on Tornado 6.4.1)
2024-07-26 19:23:28,665 User authentication hooks provided (no default user)
2024-07-26 19:23:28,671 Bokeh app running at: http://localhost:9001/tabs_example
2024-07-26 19:23:28,671 Starting Bokeh server with process id: 122065
2024-07-26 19:23:33,736 Starting Bokeh server version 3.4.2 (running on Tornado 6.4.1)
2024-07-26 19:23:33,759 User authentication hooks NOT provided (default user enabled)
Launching server at http://localhost:60725
2024-07-26 19:23:34,509 WebSocket connection opened
2024-07-26 19:23:34,509 ServerConnection created
2024-07-26 19:23:35,056 WebSocket connection opened
2024-07-26 19:23:35,057 ServerConnection created

Actually opens http://localhost:9002/tabs_example which immediately opens a new tab (leaving that tab in my browser just empty) at some random port like: http://localhost:51194/ If I refresh the 9002 port tab, I get another opened new tab in my browser with another random port like http://localhost:51907/

Meanwhile in the shell I get messages like:

Launching server at http://localhost:60777

With more random ports as every one of those tabs open.

Can someone explain me what is going on? I haven’t seen this behavior without using Tabs before.

Additionally, if I open one of the “random port” urls like http://localhost:51907/ from another browser, it skips the basic auth and just shows me the content… which is not great if I want to place anything publicly facing.

[1] Off-topic, once I run one panel serve with basic auth+cookie, any further one I run needs to have that enabled or the server does not start with errors like:

HTTPServerRequest(protocol='http', host='localhost:9002', method='GET', uri='/', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/tornado/web.py", line 1788, in _execute
    result = method(*self.path_args, **self.path_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tornado/web.py", line 3287, in wrapper
    if not self.current_user:
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tornado/web.py", line 1424, in current_user
    self._current_user = self.get_current_user()
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bokeh/server/views/auth_request_handler.py", line 71, in get_current_user
    return self.application.auth_provider.get_user(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/panel/auth.py", line 938, in get_user
    user = request_handler.get_secure_cookie("user", max_age_days=config.oauth_expiry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tornado/web.py", line 840, in get_signed_cookie
    self.require_setting("cookie_secret", "secure cookies")
  File "/usr/local/lib/python3.11/site-packages/tornado/web.py", line 1673, in require_setting
    raise Exception(
Exception: You must define the 'cookie_secret' setting in your application to use secure cookies
1 Like

Quickly skimmed:

If you use pn.serve, just run python tabs_example.py

If you use .servable() use panel serve tabs_example.py

1 Like

Damn, good sight mate!

-insert meme of Legolas! what do your elf eyes see-