Reputation: 1509
I'm porting one of my Perl CGI scripts to Python Flask and am using Miguel Grinberg's flask-httpauth which works well but I need to extract the usernames and passwords from a Postgres table rather than hard coding the credentials like the example in the docs. I've used flask-sqlalchemy and werkzeug to encrypt passwords and store them in the table but can't decipher how to replace the hard coded array.
The hard coded array looks like this:
users = { "tag": generate_password_hash("Doofus"), "thomas": generate_password_hash("LostAtSea") }
I compared the passwords stored in the Pg table with a py script that creates them and they are identical. That much seems to work.
This crude but ineffective snippet does not cause the script to barf but it fails - the auth screen pops up repeatedly until I click cancel.
users = [] db_users = session.query(User).all() for db_user in db_users: string = ('"' + db_user.login + '":', db_user.pass_word) users.append(string)
In the above fiasco I concatenated the string var because append() takes only one arg. I imagine this is not helping things.
Any tips appreciated.
Upvotes: 0
Views: 17