SyntaxError: Invalid Syntax Query

I am trying to access a remote database through Streamlit but I keep getting this syntax error for the query line I have built into the code. This code originated in Jupyter notebook but I wanted to display the tab in a Streamlit format.

Share a clear and concise description of the issue. Aim for 2-3 sentences.

Steps to reproduce

Code snippet:

st.dataframe(	
    #mydb = connector.connect(host="192.168.1.8", database = 'FreeWeibo',user="abc", passwd="abc",use_pure=True)
    mydb = connector.connect(host="96.242.223.246", database = 'FreeWeibo',user="abc", passwd="abc",use_pure=True)
query = "Select * from FreeWeiboPosts"
data = pd.read_sql(query,mydb)
mydb.close() #close the connection

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

I get this error from the get go of running the above code.
Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

File "C:\Users\avida\FreeWeibo\FreeWeibo.py", line 27
  query = "Select * from FreeWeiboPosts"
  ^
SyntaxError: invalid syntax

Debug info

  • Streamlit version:1.15.1
  • Python version:3.9.15
  • Using Conda
  • OS version: Windows 10
  • Browser version: Crome

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.

Links

  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

Appears that you simply forgot to add a closing ) in your first line. Try removing that first line, and unindenting the mydb line, and it may work.

I am still getting that same error. What I am trying to accomplish is to display the data from the database into a table or chart of some sort.

It looks to me like there is too much going on inside st.dataframe. Try handling your connection and querying of data first, then feed the result into st.dataframe.

mydb = connector.connect(host="96.242.223.246", database = 'FreeWeibo',user="abc",  
                         passwd="abc",use_pure=True)
query = "Select * from FreeWeiboPosts"
data = pd.read_sql(query,mydb)
st.dataframe(data)
mydb.close() #close the connection

Thank you so much this is exactly what I needed!