2
我写了一个Ruby脚本,试图连接到Heroku上托管的Postgres数据库。Ruby隐藏的输入密码
如果我使用硬编码密码,或者如果我使用gets
加载密码,一切工作正常。 但是,如果我加载使用IO.noecho
密码,我得到以下异常:
storing.rb:11:in `initialize': FATAL: password authentication failed for user "***" (PG::ConnectionBad)
FATAL: no pg_hba.conf entry for host "****", user "***", database "***", SSL off
from storing.rb:11:in `new'
from storing.rb:11:in `create_conn'
from fetch_currencies.rb:11:in `<main>'
这里是我的代码:
def create_conn(password)
conn = PGconn.connect(
:host => '***',
:port => 5432,
:dbname => '***',
:user => '***',
:password => password)
return conn
end
puts 'Postgres DB password:'
pass = STDIN.noecho(&:gets)
conn = create_conn(pass)
我试图加载它后打印密码,以及检查它是否是一个字符串,一切似乎都很好。可能是什么问题呢?