# How to extract headers in streamlit app

**URL:** <https://discuss.streamlit.io/t/how-to-extract-headers-in-streamlit-app/32157>\
**Category:** Using Streamlit\
**Created:** [October 18, 2022, 3:38pm UTC](https://discuss.streamlit.io/t/how-to-extract-headers-in-streamlit-app/32157 "2022-10-18T15:38:11Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![snehankekre](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/snehankekre/32/6504_2.png) [@snehankekre](https://discuss.streamlit.io/u/snehankekre)\
**Post date:** [October 19, 2022, 6:23am UTC](https://discuss.streamlit.io/t/how-to-extract-headers-in-streamlit-app/32157/7 "2022-10-19T06:23:25Z")

</div>

The fix was created after the 1.13.0 release. You will have to either wait for the next release on the 27th or try to see if the fix is available in `streamlit-nightly`.

The last option is to try workarounds described in this GitHub issue:

> <https://github.com/streamlit/streamlit/issues/5166>
>
> \### Problem
> 
> In previous versions, we used the following code to retrieve the …access token header from the websocket headers:
> 
> \`\`\`python
> from streamlit.server.server import Server
> from streamlit.scriptrunner.script\_run\_context import get\_script\_run\_ctx
> 
> def get\_access\_token() -\> Optional\[str\]:
> """Gets the access token from the websocket headers, if possible."""
> # Get headers
> session\_id = get\_script\_run\_ctx().session\_id # type: ignore
> server = Server.get\_current()
> session\_info = server.\_get\_session\_info(session\_id)
> if session\_info.ws is None: # type: ignore
> # At first page load, this is None (at least until #4099 is fixed)
> st.markdown("Unable to get session websocket. Please refresh the page.")
> st.stop()
> headers = session\_info.ws.request.headers # type: ignore
> 
> # Get access token
> access\_token\_key = "X-Access-Token"
> if access\_token\_key in headers.keys():
> access\_token = headers\[access\_token\_key\]
> else: # development environment
> access\_token = None
> 
> return access\_token
> \`\`\`
> 
> We noticed the import paths changed for scriptrunner and server, however \`Server.get\_current()\` apparently no longer exists. Is there still a way for us to get the websocket headers? 
> 
> This is very important for us, as we use the access token for group-based access control and there isn't another way for us to easily get the same information that we've been able to find. 
> 
> Currently we've just pinned the version to 1.11.1 but that's not great long-term as we do like to take advantage of new features as they come out.
> 
> \### Solution
> 
> \*\*MVP:\*\* Whatever is easiest for us to be able to get the access token from the websocket headers.
> 
> \*\*Possible additions:\*\* Potentially some documentation support for the server side of the app would be great.

But I would wait for the next release or check `streamlit-nightly`.

---

_[View the full topic](https://discuss.streamlit.io/t/how-to-extract-headers-in-streamlit-app/32157)._
