[英]SQLAlchemy (psycopg2.OperationalError) fe_sendauth: no password supplied
I'm having this authentication issue when trying to connect to a postgres db using sqlalchemy.尝试使用 sqlalchemy 连接到 postgres 数据库时遇到此身份验证问题。 This is how I'm connection:这是我的连接方式:
db_url = 'postgresql+psycopg2:///<role>:<pass>@localhost:5432/basketball'
Engine = create_engine(db_url, echo=False)
SessionMaker = ORM.sessionmaker(bind=Engine, autoflush=False)
Session = ORM.scoped_session(SessionMaker)
This is how I set up /etc/postgresql/9.3/main/pg_hba.conf
这就是我设置/etc/postgresql/9.3/main/pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Then, when accessing the db I get:然后,在访问数据库时,我得到:
SQLAlchemy (psycopg2.OperationalError) fe_sendauth: no password supplied
As @univerio commented , the problem is the structure of the connection url.正如@univerio 评论的那样,问题在于连接 url 的结构。
The standard url structure is标准的 url 结构是
dialect+driver://username:password@host:port/database
The url网址
db_url = 'postgresql+psycopg2:///<role>:<pass>@localhost:5432/basketball'
describes a Postgresql database named <role>:<pass>@localhost:5432/basketball
with no explicit credentials or hostname defined, hence the error message.描述了一个名为<role>:<pass>@localhost:5432/basketball
的 Postgresql 数据库,没有定义明确的凭据或主机名,因此出现错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.