

The connect() function creates a new database session and returns a new instance of the connection class. To connect to the suppliers database, you use the connect() function of the psycopg2 module. Psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060) CREATE DATABASE suppliers Connect to the PostgreSQL database using the psycopg2. The code, I run, looks like so: > connection = nnect(user = "postgres",įile "C:\Python34\lib\site-packages\psycopg2-2.6.1-p圓.4-win-amd64.egg \psycopg2\_init_.py", line 164, in connectĬonn = _connect(dsn, connection_factory=connection_factory, async=async) What is wrong with that and how can I fix it? I guess, simply changing nf and restarting Postgres is not enough. So it seems like Python (I tried psycopg2 and sqlalchemy) for some reason is bound by this 5432 port number and does not accept other port numbers.

If I switch back to port 5432 - fix nf and restart Postgres - then my Python script starts working. When, however, I try to connect to it using Python, I get an error message Is the server running on host "192.168.234.137" and accepting If I use for example Navicat, then I can easily establish connection, so Postgres running at port 5433 is reachable. I try to connect to Postgres from another machine. Syntax: conn nnect ('dbnamesuppliers userpostgres passwordpostgres') To make it convenient to use you can use the below method: 1. The machine on my local network has this IP address 192.168.234.137. Its pg_hba.conf contains this string: host all all 0.0.0.0/0 md5Īnd nf contains these lines: listen_addresses = '*' As long as you have valid credentials, you can establish a connection with few lines of code. I have Postgres up and running on one of my machines. Python offers at least two straightforward ways to interact with a PostgreSQL database: creating a connection using pycopg2 package generating and engine through the sqlalchemy package.
