St.secrets["postgres"] is throwing invalid directory on windows

Hi Everyone,

For the first time, i am trying to connect postgres DB using st.secrets[β€œpostgres”] and end up with invalid directory. Error looks legitimate but not sure why its adding β€œ\” instead of β€œ\” to the directory.

here is my secrets file structure in vscode on windows
C:\Users\E57036\Desktop\Python_Work\Streamlit_Dashboard\.streamlit\secrets.toml

[
postgres
]
host=""
port= 
dbname=""
username=""
password=""

here is the code.

import streamlit as st

import psycopg2

def init_connection():

    return psycopg2.connect(**st.secrets["postgres"])

after running my file via streamlit run or as a python file, i am getting below error

PS C:\Users\E57036\Desktop\Python_Work\Streamlit_Dashboard> python .\db_connect.py
2021-12-22 11:20:02.004
  Warning: to view this Streamlit app on a browser, run it with the following
  command:

    streamlit run .\db_connect.py [ARGUMENTS]
Traceback (most recent call last):
  File ".\db_connect.py", line 8, in <module>
    print(init_connection())
  File ".\db_connect.py", line 5, in init_connection
    return psycopg2.connect(**st.secrets["postgres"])
  File "C:\Users\E57036\AppData\Roaming\Python\Python37\site-packages\streamlit\secrets.py", line 152, in __getitem__
    return self._parse(True)[key]
  File "C:\Users\E57036\AppData\Roaming\Python\Python37\site-packages\streamlit\secrets.py", line 89, in _parse
    with open(self._file_path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\E57036\\Desktop\\Python_Work\\Streamlit_Dashboard\\.streamlit\\secrets.toml'

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.