I'm trying to pull data into a pandas dataframe from a pgadmin database using psycopg2. My .py file runs normally in terminal, but when I run it in python interactive (vs code) or jupyter notebooks I get the following error.
Code:
with psycopg2.connect(conn_string) as conn:
sql = "SELECT * FROM table"
df = pd.read_sql_query(sql, conn)
Error:
OperationalError
---> 19 with psycopg2.connect(conn_string) as conn:
20 sql = "SELECT * FROM table"
21 df = pd.read_sql_query(sql, conn)
//anaconda3/lib/python3.7/site-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
124
125 dsn = _ext.make_dsn(dsn, **kwargs)
--> 126 conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
127 if cursor_factory is not None:
128 conn.cursor_factory = cursor_factory
OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Does anyone know why this could be the case? When I open python interactive in vs code, I see this error as well:
Jupyter kernel cannot be started from 'Python 3.7.4 64-bit'.
Using closest match Python 3.7.3 64-bit ('anaconda3': conda) instead.
Error starting original kernel: Error: Module 'notebook' not installed.