Streamlit AttributeError: 'NoneType' object has no attribute 'session_id'

I am trying to save my session_id in a variable from get_report_ctx() , but I get the following error:

AttributeError: 'NoneType' object has no attribute 'session_id'

These are the libraries of streamlit I use and the command that returns me the above error:

import streamlit as st
from streamlit.report_thread import get_report_ctx
from streamlit.server.server import Server
import streamlit.legacy_caching.hashing

SESSION_ID = get_report_ctx().session_id

My streamlit version is 1.3.1. Any help would be greatly appreciated.