I have set up a temporary Postgres database for test purposes on my computer using Docker and the following commands:
1)
sudo docker run --name some-postgres6 -e POSTGRES_PASSWORD=mysecretpassword -p 5430:5432 postgres:9.1 -d postgres
2)
sudo docker run -it --rm --link some-postgres6:postgres postgres psql -h postgres -U postgres
I want to connect to the database using Python :
from sqlalchemy.engine import create_engine
import psycopg2
engine = create_engine('postgresql+psycopg2://postgres:mysecretpassword@localhost/mydb?port=5432') ### IMPORTANT!!!
connection = engine.connect()
Then I'm getting this error:
psycopg2.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
This same piece of code used to work on my other machine where I was running Ubuntu. I guess this has to do with windows. I am running Windows 10 Home (not experienced with Windows) and using Docker toolbox.