My main task is to convert or ingest the dataframe to postgressql database
I want to make a connection of the database using sqlalchemy so I want to make a connection with my postgressql database using below code.Kindly help me with this error. These are the details of my pgadmin: server name:test username:postgre passoword:password port:5432 host:localhost In the test server I have 2 databases which are postgre and stores in that I want to ingest the dataframe to the stores database
import sqlalchemy #package to access the sql databases via Python
import psycopg2
#connect to database
engine = sqlalchemy.create_engine("postgresql://postgres:password@localhost/stores")
#verify there are no existing tables
print(engine.table_names())
This is the error I am getting after running the above code
OperationalError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection)
2335 try:
-> 2336 return fn()
2337 except dialect.dbapi.Error as e:
40 frames
OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
OperationalError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
128 if cursor_factory is not None:
129 conn.cursor_factory = cursor_factory
--> 130
131 return conn
OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
(Background on this error at: http://sqlalche.me/e/13/e3q8)