1

I am trying to connect and read from a remote postgreSQL. I do not want to read from a local csv file. I am stuck at this point. I am working on a dash app. to read from local :

df = pd.read_csv('constituents.csv')

but now I want to read from a remote postgreSQL server.

hurpey
  • 11
  • 2

1 Answers1

0

This is a duplicate of: How to connect to a remote PostgreSQL database through SSL with Python

import psycopg2

conn = psycopg2.connect(dbname='yourdb', user='dbuser', password='abcd1234', host='server', port='5432', sslmode='require')

In this case sslmode specifies that SSL is required.

To perform server certificate verification you can set sslmode to verify-full or verify-ca. You need to supply the path to the server certificate in sslrootcert. Also set the sslcert and sslkey values to your client certificate and key respectively.

It is explained in detail in the PostgreSQL Connection Strings documentation (see also Parameter Key Words) and in SSL Support.

Does that make sense?

So basically you are going to create a remote connection to the database. Then you can use the variable "conn" to make Queries. Then you can take the results from the query and throw them into your pandas dataframe.

Crimson_Hawk
  • 133
  • 1
  • 2
  • 10