Postgres Connection URL not compatible with Python database drivers

Issues information

Your issue
I wanted to create a database in Qovery. I grabbed the db_url from the UI.

DB_URL = "postgresql://postgres:_Ij=de-6S8B$avgXtFN?@U-+0gnAZ0x!@z3baa5944-postgresql.qovery.io:5432/postgres"
(Don’t worry, this database does not exist in Qovery anymore.)

I’m getting an error.

File "/home/harshitsinghai/.pyenv/versions/3.9.5/lib/python3.9/urllib/parse.py", line 178, in port
    raise ValueError(message) from None
ValueError: Port could not be cast to integer value as '_Ij=de-6S8B$avgXtFN'

I deleted the database, created a new one, and tried again with the new db_url, But I’m getting the same error.

I think the db_password should be encoded.

It was working fine when I was using Heroku. I was directly using Heroku Postgres URL, but shifting database from Heroku to Qovery lead to this error.

Can someone point out what I’m doing wrong?

Code Snippet

QOVERY_URL = "postgresql://postgres:U8T%2T#YjO#-ep-MjGBcJ_@!fgczi!%g@z794a99a3-postgresql.qovery.io:5432/postgres"
database = databases.Database(QOVERY_URL)
metadata = sqlalchemy.MetaData()

engine = sqlalchemy.create_engine(QOVERY_URL)

Describe here your issue
Unable to connect to Postgres using Python database driver.

Dockerfile content (if any)

specify here your dockerfile content

Hey dude, you literally gave your db credentials. I suggest you to pls delete that db & make a new one.

And regarding your error, I think it could be due to the @ in your db’s password,
I would suggest you to delete that db & make a new one already.

@pjeziorowski
I think its a backend issue, while assigning password, I think its better to avoid @ in it.

I deleted the DB before posting the credentials here.

I tried deleting the DB and creating a new one, but the problem still persisted.

It’s solved though. The problem was with password encoding. It’s a workaround but it works.

I’m using urllib.parse.quote(DB_PASSWORD) before using it. You can check the code here.

I can still access your this db, I suggest you to delete the same

Hello Harshit

Thanks for sharing this, I experienced the same problem with Ruby unable to parse the url, since the passwords have special characters in it, so some languages can’t parse it correctly.

Escaping the string did indeed work, but I had to recreate the DATABASE_URL manually instead of using the one provided by Qovery.

Be aware though, like Rachit mentioned, that your DB is still accessible :scream: