Forums

Unable to connect to Pythonanywhere PostgreSQL instance from Local

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()

It suddenly started working with the same settings.

That sounds like you may have used an incorrect username and password for several attempts in a short time. When that happens we block the IP for an hour to prevent attempts to brute-force passwords. If you had the correct credentials when the ban was lifted it would begin working.