Home > Software engineering >  User input for connection string
User input for connection string

Time:07-12

I am trying to create a string to connect to a database. The script is supposed to ask the user for their credentials and use those. However the code below isn't working:

def remote_data():
    # ask user for credentials
    user = input('user: ')
    password = input('password: ')
    # creating a string with parameters to connect to the database
    conn_string = "host='host' dbname='name' user={user} password={password}"
    ...

Anyone know what I am doing wrong?

CodePudding user response:

So yes I am not the brightest, I forgot the f before the f-string. Thanks to those who commented!

CodePudding user response:

 conn_string = f"host='host' dbname='name' user={user} password={password}"

This should work.

  • Related