! mkdir -p ~/.postgresql && wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" -O ~/.postgresql/root.crt && chmod 0600 ~/.postgresql/root.crt
import psycopg2
import os
try:
connection = psycopg2.connect(user=os.environ["OUR_POSTGRES_USER"],
password=os.environ["OUR_POSTGRES_PASSWORD"],
host=os.environ["OUR_POSTGRES_HOST"],
port=os.environ["OUR_POSTGRES_PORT"],
database=os.environ["OUR_POSTGRES_DATABASE"])
with connection.cursor() as cursor:
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record)
except (Exception, psycopg2.Error) as error:
print ("Error while connecting to database", error)