'how to fix a operational_error?

this is my code to search wallstreetbets reddit page

from psaw import PushshiftAPI
import config
import psycopg2
import psycopg2.extras


connection = psycopg2.connect(host=config.DB_HOST, database=config.DB_NAME, 
user=config.DB_USER, password=config.DB_PASS)
cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute("""
  select * from stock
""")

This is the error

psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 
failed: Connection refused Is the server running on that host and accepting TCP/IP 
connections?

and this is the config.py file

DB_HOST = 'localhost'
DB_USER = 'postgres'
DB_PASS = 'password'
DB_NAME = 'etfdb'

Please let me know if you have any ideas.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source