import os
import datetime
from flask import Flask, render_template, redirect, url_for
#from database import DatabaseConnection
#from models import kayıt
from forms import LoginForm
import psycopg2 as p
conn=p.connect(dbname='app_db', user='postgres', host='localhost', password='samet', port=5432)
conn.autocommit=True
cur=conn.cursor()
conn'and line
psycopg2.OperationalError: could not connect to server: Connection refused
use; postgresql:9.6.5 python:3
If I only run postgre with the info, but it is not running in python
thank you
Sorry, I should have explained a little more clearly. I'm dealing with a docker. And I have 3 containers, but I am trying to use python container via PostgreSQL. I want to use psycopg2 for this. But I am getting such an error. My login information is correct. I checked.
Figure out how to solve this problem :
according to this answer:
Postgres is not running in the same container as the flask application, that why it cannot be acceded via localhost. we should find the IP address of the docker container with flask and add it, or just add Postgres or volume_name in place of localhost.
So your connection should be like this :
conn=p.connect(dbname='app_db', user='postgres', host='volume_name_of_postgres_in_docker_compose', password='samet', port=543
Are you sure all the arguments you are passing to the psycopg2
connect
function are correct?
conn=p.connect(dbname='app_db', user='postgres', host='localhost', password='samet', port=5432)
The database name, username, host, password, and port all could possibly be incorrect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With