I am getting this error when executing my code in Python.
Here is my Python - DataBaseHelper.py:
import psycopg2
#class
class DataBaseHelper:
database = "testdata";user = "test";password = "pass123"; host = "mtest.75tyey.us-east-1.rds.amazonaws.com"
#create and return the connection of database
def getConection(self):
self.conn = psycopg2.connect(database=self.database, user = self.user, password = self.password, host = self.host, port = "5432")
return self.conn
Then I am importing this file and using in another python file - MyScript.py:
import sys
import uuid
from DBHelper import DataBaseHelper
from ExecutionLogHelper import ExecutionLogHelper
from GotUtility import GotUtility
class MyScript:
def __init__(self,):
self.con = DataBaseHelper().getConection()
self.logHelper = ExecutionLogHelper()
self.uuid = self.logHelper.Get_TEST_Run_Id()
When I run my code concurrently, it gives me this error:
psycopg2.errors.AdminShutdown: terminating connection due to administrator command
SSL connection has been closed unexpectedly
I am not able to understand why am I getting this error. When I run the Python program again, it works. And I checked the Postgres server is in running, no restart, no signal to shutdown. This keeps on happening every few hours for me.
This is happening because psycopg2 is try to connect to AWS Postgresql over SSL and failing to do so.
def getConection(self):
self.conn = psycopg2.connect(database=self.database,
user = self.user,
password = self.password,
host = self.host,
port = "5432",
sslmode="disable")
return self.conn
rds.force_ssl
= 1. If you enable set rds.force_ssl
all non-SSL connections are refused. In that case try connecting using something like this:$ psql -h testpg.cdhmuqifdpib.us-east-1.rds.amazonaws.com -p 5432 "dbname=testpg user=testuser sslrootcert=rds-ca-2015-root.pem sslmode=verify-full"
For more on how to connect to AWS RDS over ssl using various drivers : AWS RDS SSL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With