Question

Is there an option in psycopg2 (in the connect() method) similar to psql -w (never issue a password prompt) and -W (force psql to prompt for a password before connecting to a database)?

Était-ce utile?

La solution

psycopg2 will never prompt for a password - that's a feature of psql, not of the underlying libpq that both psql and psycopg2 use. There's no equvialent of -w / -W because there's no password prompt feature to turn on/off.

If you want to prompt for a password you must do it yourself in your code: trap the exception thrown when authentication fails because a password is required, prompt the user for a password, and reconnect using the password. That's what psql does anyway, if you take a look at the sources.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top