Python - psql prompt for password even if it got it
<p>I'm working on a small code, which have to: </p>

<ul>
<li>Connect with SFTP</li>
<li>execute command on PostgreSQL (password protected)</li>
</ul>

<p>I am willing to use password as a plain text.</p>

<p>For the moment my code is:</p>

<pre><code>import pysftp

command = "... some SQL command"

sftp= pysftp.Connection('server_name', username='username', password='password')
sftp.execute("export PGPASSWORD='password_to_psql'")
sftp.execute("psql -h 127.0.0.1 -d {} -U {} -W -c "{}"").format(database_name, user_name, command)
sftp.close()
</code></pre>

<p>I thought it was good idea, but when i type proper command in terminal, shell prompts for password (but is not required, when i 'enter', everything is executed.</p>

<p>Does anyone knows how can i 'disable' prompts, which are not required?</p>

<p><code>psql</code> has a <code>--no-password</code> option, which can also be specified as <code>-w</code>.</p>

<p>It looks like you might have misspelled <code>-w</code> as <code>-W</code>, which has the opposite effect.</p>

python postgresql pysftp