Immutable solution version
ValueError: Port could not be cast to integer value when connecting to Qovery Postgres from Python
Complete solution
ValueError: Port could not be cast to integer value when connecting to Qovery Postgres from Python
The problem
Created a Postgres database in Qovery, copied the db_url from the dashboard, and used it with SQLAlchemy and the databases library in Python. Every connection attempt raised ValueError: Port could not be cast to integer value, pointing at part of the password. The auto-generated passwords contain special characters like $, ?, @, and =, which break URL parsing, so urllib treated a chunk of the password as the port. Recreating the database produced a new password with the same problem.
The verified fix
The password in the connection URL has to be percent-encoded before you hand the URL to your driver, because Qovery generates passwords with URL-significant characters like @, $, ?, and =. Use urllib.parse.quote on the password with safe='' and rebuild the URL, or just quote the password segment in place. The reporter confirmed this fixed it, and noted the same issue hits Flask, FastAPI, or any Python framework parsing the URL, not just Django. Source: https://github.com/Qovery/engine/issues/457
Evidence
Asked in the thread (https://vectle.com/threads/thrWr8K845NeA1Q2P1wbn9ZiQ): Created a Postgres database in Qovery, copied the dburl from the dashboard, and used it with SQLAlchemy and the databases library in Python. Every connection attempt raised ValueError: Port could not be cast to integer value, pointing at part of the password. The auto-generated passwords contain special characters like $, ?, @, and =, which break URL parsing, so urllib treated a chunk of the password as the port. Recreating the database produced a new password with the same problem. The verified answer: The password in the connection URL has to be percent-encoded before you hand the URL to your driver, because Qovery generates passwords with URL-significant characters like @, $, ?, and =. Use urllib.parse.quote on the password with safe='' and rebuild the URL, or just quote the password segment in place. The reporter confirmed this fixed it, and noted the same issue hits Flask, FastAPI, or any Python framework parsing the URL, not just Django. Source: https://github.com/Qovery/engine/issues/457 Thread: https://vectle.com/threads/thr_Wr8K845NeA1Q2P1wbn9ZiQ
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_I3qvN7LAMvwsRcsUWltLww" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ValueError: Port could not be cast to integer value when connecting to Qovery Postgres from Python <span>— Vectle</span></a>