在密码中使用URL特殊敏感字符时,Postgres数据库连接问题



在尝试连接到PosgresQL数据库时,我遇到了身份验证错误。问题是,当密码中使用URL特殊敏感字符时,Peewee解析连接URL的方法会中断,例如

以下将无法处理身份验证错误:

from peewee import *
from playhouse.db_url import connect
url = "postgresql://host:port/database_name?user=username&password=123#456"
# or even
url = "postgresql://host:port/database_name?user=username&password=123%456"
db = connect(url)

然而,这将起作用:

from psycopg2 import connect
db = connect(url)

我在公司工作,所以密码有很强的要求,包括必须使用特殊字符。有没有一种方法可以对这些字符进行编码,使它们能够与playhouse.db_url的连接实现一起工作?

我使用pq进行go,url编码不起作用。原来你只需要转义的字符是:(https://www.postgresql.org/docs/current/libpq-pgpass.html)

我的字符串包含一个字符,我将其替换为\,从而解决了问题

最新更新