Hello,
I am trying to connect to the PostgreSQL instance from my local computer using Python. I have used instruction specified in the article which suggests using SSHTunnel for connecting to DB.
I am getting a connection refused error constantly. Few other times I get connection reset by peer error.
Can anyone please suggests what could be the reason behind it?
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
with sshtunnel.SSHTunnelForwarder(
ssh_address_or_host = ('ssh.pythonanywhere.com'),
ssh_username='username', ssh_password='pass',
remote_bind_address=('user.postgres.pythonanywhere-services.com',port),
) as tunnel:
connection = psycopg2.connect(
user='super', password='pass',
host='127.0.0.1', port=tunnel.local_bind_port,
database='new_db',
)
# Do stuff
connection.close()