0

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)
9
  • So like the error message says: "Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?" Commented Nov 9, 2020 at 13:17
  • how to check it? Commented Nov 9, 2020 at 13:55
  • Possibly related: stackoverflow.com/q/10823534/2144390 Commented Nov 9, 2020 at 13:58
  • btw in pgadmin of postgresql,everything is working fine. Commented Nov 9, 2020 at 14:16
  • Are the connection parameters in pgAdmin the same as what you are using in the code? Commented Nov 9, 2020 at 15:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.