简体   繁体   English

Python 和 Postgresql:OperationalError:fe_sendauth:未提供密码

[英]Python and Postgresql: OperationalError: fe_sendauth: no password supplied

I know there are a lot of similar questions on StackOverflow, but I have read and re-read them, and I cannot seem to solve my particular issue.我知道 StackOverflow 上有很多类似的问题,但我已经阅读并重新阅读了它们,但我似乎无法解决我的特定问题。

I am developing a Python application that uses Peewee and Psycopg2 to access PostGresQL databases.我正在开发一个使用 Peewee 和 Psycopg2 访问 PostGresQL 数据库的 Python 应用程序。 This is all being run in an Ubuntu Vagrant Virtual Machine.这一切都在 Ubuntu Vagrant 虚拟机中运行。

I keep getting this error when I try to add a user via Python:当我尝试通过 Python 添加用户时,我不断收到此错误:

peewee.OperationalError: fe_sendauth: no password supplied peewee.OperationalError:fe_sendauth:未提供密码

Here is the code where I try to add a user :这是我尝试添加用户的代码:

def add_user(user, password):
    """
    :param username:
    :param password:
    :return:
    """
    try:
        #add user to admin user table
        #AdminUserModel.create(username=user, password=password)

        # add user to psql
        conn = connect_to_db('postgres', 'postgres')
        cursor = conn.cursor()
        add_query = "CREATE ROLE %s WITH CREATEDB LOGIN PASSWORD %s"
        add_data = (AsIs(user), password)
        cursor.execute(add_query, add_data)

    except IntegrityError:
        return False

    return True

def connect_to_db(db_name, username):
    conn = psycopg2.connect(dbname=db_name, user=username)
    conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
    return conn

I have changed my pg_hba.conf file to:我已将pg_hba.conf文件更改为:

# Database administrative login by Unix domain socket
local   all             postgres                                trust

# "local" is for Unix domain socket connections only
local   all             all                                     md5

# IPv4 local connections:
host    all             vagrant         127.0.0.1/32            trust
host    all             all             127.0.0.1/32            md5

# IPv6 local connections:
host    all             vagrant         ::1/128                 trust
host    all             all             ::1/128                 md5

And have restarted my postgresql server.并重新启动了我的 postgresql 服务器。

Here is my Vagrantfile :这是我的流浪文件

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.provider :virtualbox do |vb|
    # use for debugging the vm
    # vb.gui = true

    # speed up networking
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
  end

  config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update
    sudo apt-get install -y python-software-properties
    sudo apt-get update -y
    # sudo apt-get upgrade -y

    sudo apt-get install -y postgresql postgresql-contrib postgresql-client libpq-dev
    sudo sed -i "s/#listen_address.*/listen_addresses '*'/" /etc/postgresql/9.3/main/postgresql.conf
    sudo cp /home/vagrant/cs419-project/vagrant_files/pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf

    sudo service postgresql restart

    # createuser -U postgres -s vagrant
    sudo -u postgres psql -c "CREATE ROLE vagrant SUPERUSER LOGIN PASSWORD 'vagrant'"
    sudo su postgres -c "createdb -E UTF8 -T template0 --locale=en_US.utf8 -O vagrant cs419"

    sudo apt-get install -y python-pip python-psycopg2
    sudo pip install peewee
  SHELL

  config.vm.synced_folder ".", "/home/vagrant/cs419-project", id: "vagrant",
    owner: "vagrant",
    group: "admin",
    mount_options: ["dmode=775,fmode=664"]
end

Please, any help you can give is much appreciated!拜托,非常感谢您提供的任何帮助!

NOTE: The weirdest part is this all seemed to be working before and then I don't know what I changed but it stopped working.注意:最奇怪的部分是这一切似乎以前都在工作,然后我不知道我改变了什么,但它停止工作了。

在pg_hba.conf文件中,为fe_sendauth用户使用trust访问方法

Can you try adding in a password changing this 您可以尝试添加更改此密码的密码吗?

conn = psycopg2.connect(dbname=db_name, user=username)

to this? 这个?

conn = psycopg2.connect(dbname=db_name, user=username, password=password)

this worked for me using my password for the postgres server 这对我使用postgres服务器的密码

Old Host,老主人,

 host all all 127.0.0.1/32 md5
 host all all ::1/0 md5

Change this host in the file "/etc/postgresql/13/main/pg_hba.conf"在文件“/etc/postgresql/13/main/pg_hba.conf”中更改此主机

Solution:-解决方案:-

step1:
    sudo vi /etc/postgresql/13/main/pg_hba.conf

step2:
    New Host, just change the md5 to trust like given below,
    host all all 127.0.0.1/32 trust
    host all all ::1/0 trust

step3: 
    save the file.

This method works for me.这种方法对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 psycopg2.OperationalError:fe_sendauth:未提供密码 - psycopg2.OperationalError: fe_sendauth: no password supplied AWS-DJANGO-格式错误:OperationalError:fe_sendauth:未提供密码 - AWS - DJANGO - Error in formatting: OperationalError: fe_sendauth: no password supplied SQLAlchemy (psycopg2.OperationalError) fe_sendauth:未提供密码 - SQLAlchemy (psycopg2.OperationalError) fe_sendauth: no password supplied PostgreSQL错误-psql:fe_sendauth:未提供密码 - PostgreSQL Error - psql: fe_sendauth: no password supplied Django 4 使用密码文件连接到 Postgresql:“fe_sendauth:未提供密码” - Django 4 connection to Postgresql using passfile: "fe_sendauth: no password supplied" fe_sendauth:Composer 中没有提供密码 - fe_sendauth: no password supplied in Composer django.db.utils.OperationalError:fe_sendauth:迁移 django 应用程序时未提供密码 - django.db.utils.OperationalError: fe_sendauth: no password supplied when migrating django app Django psycopg2.OperationalError:fe_sendauth错误,但未连接到PostgreSQL数据库 - Django psycopg2.OperationalError: fe_sendauth error but not connecting to postgresql database 将postgres作为Docker服务运行时,“psql:fe_sendauth:没有提供密码” - “psql: fe_sendauth: no password supplied” when running postgres as a Docker service Django fe_sendauth:未提供密码错误,无法连接到 postgres 数据库 - Django fe_sendauth: no password supplied error, unable to connect to postgres database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM