1

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.

  • Pretty straight forward error message, there is no Postgres server running on that host and port. Possible causes 1) Server is not actually running. Verify that the service/process is up. 2) It is running but listening on different port. Verify `port` setting in `postgresql.conf`. 3) It is not listening on `localhost` verify `listen_addresses` in `postgresql.conf`. See [postgresql.conf connection settings](https://www.postgresql.org/docs/current/runtime-config-connection.html) for more information. Also to your question add Postgres version, OS and method of Postgres install. – Adrian Klaver Feb 19 '22 at 18:31

0 Answers0