TypeError: Expected user agent to be a string, got 0
File "/usr/_streamlit_playground/nginx_test_page.py", line 26, in nginx_test_page_init user_agent = parse(ua_string) File "/usr/_streamlit_playground/streamlit_dev_env/lib64/python3.9/site-packages/user_agents/parsers.py", line 268, in parse return UserAgent(user_agent_string) File "/usr/_streamlit_playground/streamlit_dev_env/lib64/python3.9/site-packages/user_agents/parsers.py", line 136, in init ua_dict = user_agent_parser.Parse(user_agent_string) File "/usr/_streamlit_playground/streamlit_dev_env/lib64/python3.9/site-packages/ua_parser/user_agent_parser.py", line 227, in Parse entry = _lookup(user_agent_string) File "/usr/_streamlit_playground/streamlit_dev_env/lib64/python3.9/site-packages/ua_parser/user_agent_parser.py", line 192, in _lookup raise TypeError(f"Expected user agent to be a string, got {ua!r}")
Code:
from streamlit_javascript import st_javascript
from user_agents import parse
ua_string = st_javascript("""window.navigator.userAgent;""")
user_agent = parse(ua_string)
st.write(ua_string)
st.session_state.is_session_pc = user_agent.is_pc
st.info(st.session_state.is_session_pc)
Version: There is no version info
Probably a strict nginx configuration is causing it, but still, it should not be an issue.
Does ua_string = st_javascript("""window.parent.navigator.userAgent;""") work? Becuase the code is run in an iframe, and you want the userAgent from the browser window.