text="odoo15"
message=text.encode()
proc = Popen(["psql",
"-h","localhost",
"-d", "database",
"-U", "User",
"-f", "/path/dump.sql"], stdin=PIPE)
proc.communicate(input=message)
Before I execute that code I am connected with the database using psycopg. I want to execute sql code from a file onto a database to create tables and fill them with data coming from the dumb file. The trouble I have is that I still need to manually enter the password in the console for this code to work. I do not understand why it is not taking the password from proc.communicate. I would be really grateful for some help.
I also tried it with subprocess.run and having input as an argument but had the same problem. My first idea was to use the /i command from psql but since I cannot execute psql in psycopg it did not work. I also tried:
cursor.execute(open("/path/dump.sql", "r").read())
and
os.system("sudo -u user psql database < /path/dump.sql")
but the first could not execute because i have \ in my file and the second did also not work.