Forums

Issue Connecting PythonAnywhere Postgresql DB to Django Project

I followed the instructions in the article "Getting Started with Postgres" word for word but I get the error message:

OperationalError: connection to server at "gioeuresti-3742.postgres.pythonanywhere-services.com" (10.0.0.64), port 13742 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections?

Any suggestions?

How are you trying to connect? Could you share the code?

Thanks for the quick response, here is my code.

DATABASES = { 
    "default": { 
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "photomdb",
        "USER": "photomadmin",
        "PASSWORD": "*********",
        "HOST": "gioeuresti-3742.postgres.pythonanywhere-services.com",
        "PORT": "13742",
    }
}

Looks like your db is up and running. Are you able to open a Postgres console from the databases page?

Looks like your db is up and running. Are you able to open a Postgres console from the databases page?

Yup, all I did was enter the commands suggested in the article:

CREATE DATABASE myappdb;

"CREATE USER myappuser WITH PASSWORD 'a-nice-random-password';

ALTER ROLE myappuser SET client_encoding TO 'utf8'; ALTER ROLE myappuser SET default_transaction_isolation TO 'read committed'; ALTER ROLE myappuser SET timezone TO 'UTC';

GRANT ALL PRIVILEGES ON DATABASE myappdb TO myappuser;"

Although I changed the names of some things such as the database name.

Do you try to connect from web app hosted on PythonAnywhere?

No I was trying to connect from my locally hosted Django project.

In such case you need an SSH tunnel to do so, see this help page for more details.