I am currently using python and Flask to query a database. I have the following function:`
def get_details(username):
conn = database_connect()
if(conn is None):
return ERROR_CODE
cur = conn.cursor()
val = None
try:
cur.execute("""SELECT username, name, age, address
FROM users
WHERE username = %s;""",(username))
val = cur.fetchone()
except:
print("failed to retrieve")
cur.close()
conn.close()
return val
username in the "users" table is a primary key and hence only a tuple is returned by this query (confirmed this by manually querying in postgress). However "val" is always a "none". I have also tried to use fetchall() but this doesn't work either.
Is there something wrong with the query itself? How should I code this?