a year ago
conn = connect(dsn, connectionfactory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: Host desconocido.
5 Replies
a year ago
If you are connecting to your database from anything that's not running inside of your Railway project you will need to use the DATABASE_PUBLIC_URL
variable to connect.
a year ago
Hola Brody thank for your answer but unfortunatly if a use database_public_url in my .env I have this issue ' conn = connect(dsn, connectionfactory=connection_factory, **kwasync)
django.db.utils.OperationalError' if i copy that url in my django settings database I have the same connection error, and I have being using both version of psycopg2 or 3 and the same result... here some facts...I have changed the data for xxxxxxxxxxxs
DATABASES = {
"default": {
#"ENGINE": "django.db.backends.sqlite3",
#"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": 'django.db.backends.postgresql',
"NAME": 'railway',
"USER": 'postgres',
"PASSWORD": os.environ.get('DB_PASSWORD_ME'),
"HOST": os.environ.get('DATABASE_PUBLIC_URL'),
"PORT": '5432',
}
}
DATABASES = {
"default": {
#"ENGINE": "django.db.backends.sqlite3",
#"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": 'django.db.backends.postgresql',
"NAME": 'railway',
"USER": 'postgres',
"PASSWORD": os.environ.get('DB_PASSWORD_ME'),
"HOST": 'postgresql://postgres:xxxxxxxxxxxxxxxxxxx@tranquil.proxy.rlwy.net:34833/railway',
"PORT": '5433',
}
}
pip freeze
asgiref==3.8.1
Django==5.0.6
gunicorn==22.0.0
packaging==24.1
pillow==10.3.0
psycopg==3.2.1
pycryptodome==3.20.0
python-dotenv==1.0.1
sqlparse==0.5.0
typing_extensions==4.12.2
tzdata==2024.1
whitenoise==6.7.0
if i use pip install psycopg2-binary
I get this issue \site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
Status changed to Solved brody • 12 months ago