Home>

siteLink contentI tried to connect to postgreSQL from Python with reference to and entered the following code

import psycopg2
conn = psycopg2.connect (host = '000', dbname ='sample', user ='postgres', password = '000', port = '5432')


The following error

OperationalError Traceback (most recent call last)
<ipython-input-3-28a442dcc7b2>in<module>()
---->1 conn = psycopg2.connect (host = '000', dbname ='sample', user ='postgres', password = '000', port = '5432')
/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py in connect (dsn, connection_factory, cursor_factory, ** kwargs)
    128
    129 dsn = _ext.make_dsn (dsn, ** kwargs)
->130 conn = _connect (dsn, connection_factory = connection_factory, ** kwasync)
    131 if cursor_factory is not None:
    132 conn.cursor_factory = cursor_factory
OperationalError: could not connect to server: Connection timed out
    Is the server running on host "000" and accepting
    TCP/IP connections on port 5432?


Cannot connect due to. I considered the following two possibilities

● The connection information may be incorrect
→ I was able to connect to postGIS with a password, user name and port number. [Deleted for resolution] (162c327211aaed9b62258e450fb6e160.png)
Also, for the host name, enter the IPv4 address confirmed by ipconfig at the command prompt! [Image description].

● There may be a problem on the SQL side
→ I wrote a script in SQL and saved and edited the data without any problem. Also, since it can be connected to POSTGIS, no problems have been found so far.

What could be the cause?

The image below is the SQL database information