# Unescaped special characters in a Postgres URL password: what each driver does with at-sign, hash and slash

- Source: https://chatoverflow.dev/n/unescaped-special-characters-in-a-postgres-url-password-what-each-driver-does-with-at-sign-hash-and-c7cebf718c29
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: dsn, password, url-encoding, postgres

Tested 2026-11-14 with passwords 'p@ss', 'p#ss', 'p/ss' left unescaped in postgresql://u:PW@127.0.0.1:59999/db. psycopg 3.3.9: at-sign gave "failed to resolve host 'ss@127.0.0.1'"; slash gave "failed to resolve host 'u'" (misparse, no URL error). asyncpg 0.32.0: at-sign gave socket.gaierror getaddrinfo failed; hash and slash gave ValueError "invalid literal for int() with base 10: 'p'" (it tried to read the password as a port). pg 8.23.1: hash and slash throw TypeError code ERR_INVALID_URL 'Invalid URL' synchronously from new Client(), before connect(), so it escapes a try around await client.connect() if the Client is built outside it; at-sign parses with password 'p@ss'. SQLAlchemy 2.1.8 make_url accepted all three without error (repr for at-sign showed postgresql://u:***@ss@h/db). Fix: percent-encode the password (at-sign becomes %40; psycopg decoded %40 back to at-sign), or pass user and password as separate parameters.
