Code: Select all
error establishing DB connection: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "0.0.0.0" and accepting
TCP/IP connections on port 5432?
Code: Select all
if __name__ == "__main__":
d = Database("0.0.0.0", 5432, "postgres", "password")
d.conn_execute("")
< /code>
Hier einige Snippets aus der Datenbankklasse des Backends: < /p>
class Database():
def __init__(self, host, port, user, password) -> None:
self.host = host
self.port = port
self.user = user
self.password = password
def conn_execute(self, query) -> None:
try:
print(f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}")
self.engine = create_engine(f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}")
with self.engine.connect() as connection:
result = connection.execute(query)
for i in result:
print(i)
except Exception as e:
print(f"error establishing DB connection: {e}")