postgresql SQLAlchemy 没有提供密码错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23839656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLAlchemy no password supplied error
提问by yifanwu
This is probably a silly error but I cannot seem to find a satisfying solution.
这可能是一个愚蠢的错误,但我似乎找不到令人满意的解决方案。
When running db.create_all()
, I got the following error.
运行时db.create_all()
,出现以下错误。
sqlalchemy.exc.OperationalError: (OperationalError) fe_sendauth: no password supplied None None
My database link is set as
我的数据库链接设置为
'postgresql://localhost/db_name'
This worked fine on my Mac and Heroku, but is not OK on ubuntu (digitalocean).
这在我的 Mac 和 Heroku 上运行良好,但在 ubuntu (digitalocean) 上就不行了。
Any ideas what I might be doing wrong?
任何想法我可能做错了什么?
回答by Danny W. Adair
You probably just need to remove "localhost" from your connection string:
您可能只需要从连接字符串中删除“localhost”:
'postgresql:///db_name'
That tells psycopg2 to use Unix-domain sockets. Your default configuration will use "ident" so you'll be connecting as the user that runs the script. In the default configuration, "md5" only applies to TCP connections.
这告诉 psycopg2 使用 Unix 域套接字。您的默认配置将使用“ident”,因此您将以运行脚本的用户身份进行连接。在默认配置中,“md5”仅适用于 TCP 连接。
回答by omokehinde igbekoyi
URL pattern should be:
URL 模式应该是:
postgresql://user:password@localhost:5432/database_name
pip install psycopg2
the user should be postgres or any other user you have created and intend to use
pip install psycopg2
用户应该是 postgres 或您创建并打算使用的任何其他用户
similarly for mySql it would be:
同样对于 mySql 它将是:
mysql://user:pass@localhost:3306/database_name
pip install mysql-python
pip 安装 mysql-python
回答by Craig Ringer
On your Mac, PostgreSQL was set up for trust
or peer
authentication for connections from localhost.
在您的 Mac 上,PostgreSQL 是为来自 localhost 的连接设置trust
或peer
验证的。
On your Ubuntu box it's set up for md5
authentication for connections from localhost.
在您的 Ubuntu 机器上,它设置为md5
对来自 localhost 的连接进行身份验证。
You'll want to configure a password, or change the authentication mode. See pg_hba.conf
, and the Ubuntu guide for PostgreSQL(there's a section about this error).
您需要配置密码或更改身份验证模式。请参阅pg_hba.conf
和Ubuntu PostgreSQL 指南(有一个关于此错误的部分)。
回答by Genesis
Below worked for me. Your connection to your postgres database requires a password; thus, below is what you should write..
下面为我工作。您与 postgres 数据库的连接需要密码;因此,下面是您应该写的内容..
pg_user = "magicmike"
pg_pwd = "test123"
pg_port = "5432"
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://{username}:{password}@localhost:{port}/foodversity_db".format(username=pg_user, password=pg_pwd, port=pg_port)