3

When connecting to PostgreSQL using Psycopg2 user name and password must be supplied to reach the database. When I'm working in my computer keeping password of my local database as plain text is not a problem.

But when I want to use this script in another computer I need to hide credentials. How this can be done ? Any help appreciated

h.

pault
  • 41,343
  • 15
  • 107
  • 149
Capan
  • 686
  • 1
  • 14
  • 32
  • You can use a `.pgpass` file. See [this post](https://stackoverflow.com/questions/28800880/python-connect-to-postgresql-with-libpq-pgpass). – pault Jul 18 '18 at 14:53
  • Does this answer your question? [python connect to postgresql with libpq-pgpass](https://stackoverflow.com/questions/28800880/python-connect-to-postgresql-with-libpq-pgpass) – legends2k Aug 17 '22 at 07:42

1 Answers1

1

The easiest way to hide credentials is to not store them on the public machine. Use the getpass module to prompt future you for your password.

Ben
  • 5,952
  • 4
  • 33
  • 44
  • Hi Ben, what if I want to run the script at specific time intervals like a scheduled task ? – Capan Jul 18 '18 at 16:16