gpt4 book ai didi

python - Django 和 psycopg2 : FATAL: password authentication failed for user

转载 作者:行者123 更新时间:2023-11-29 13:18:20 34 4
gpt4 key购买 nike

我在从我的 django 站点连接到我的 postgres 数据库时遇到问题。在开始之前,我已经阅读并尝试了每个网站提供的说明:

对于下述问题,您能够提供的任何帮助都将对非营利性网站的完成大有帮助。提前谢谢你。

回溯

回溯对于这篇文章来说太大了。请参阅:https://pastebin.com/fX7NY36M .

名字

kris@dask:~$ uname -a
Linux dask 4.9.36-x86_64-linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

pg_hba.conf

kris@dask:~$ sudo cat /etc/postgresql/9.5/main/pg_hba.conf
...

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
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5

wsgi.py

kris@dask:/home/dask/www/code/daskretreats_org$ cat wsgi.py
"""
WSGI config for daskretreats_org project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
from mezzanine.utils.conf import real_project_name

os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"%s.settings" % real_project_name("daskretreats_org"))

application = get_wsgi_application()

settings.py

settings.py 对于这篇文章来说太大了。请参阅:https://pastebin.com/Dynq7EvT .

测试 psycopg2 python 库

(venv) dask@dask:~/www/secrets$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> f = open("postgres_key")
>>> passwd = f.read().strip()
>>> conn = psycopg2.connect("dbname=daskretreats_org user=dask password=%s" % passwd)
>>> conn.dsn
'password=xxx user=dask dbname=daskretreats_org'

Apache 站点配置

kris@dask:~$ cat /etc/apache2/sites-enabled/daskretreats_org.conf 
<VirtualHost *:80>
ServerName daskretreats.org
Alias /static /home/dask/www/html/static
<Directory /home/dask/www/html/static>
Require all granted
</Directory>

<Directory /home/dask/www/code/daskretreats_org>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIDaemonProcess daskretreats_org python-home=/home/dask/www/venv python-path=/home/dask/www/code
WSGIProcessGroup daskretreats_org
WSGIScriptAlias / /home/dask/www/code/daskretreats_org/wsgi.py
</VirtualHost>

最佳答案

您是否为用户设置了角色并授予了用户对数据库的权限?

postgres=#
ALTER ROLE mydbuser SET client_encoding TO 'utf8';
ALTER ROLE mydbuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE mydbuser SET timezone TO 'UTC';

GRANT ALL PRIVILEGES ON DATABASE mydb TO mydbuser;

关于python - Django 和 psycopg2 : FATAL: password authentication failed for user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45951625/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com