Python: decryption failed or bad record mac when calling from Thread

Viewed 8180

I'm getting a "decryption failed or bad record mac" error in this code-fragment:

conn = psycopg2.connect(...)
cursor = conn.cursor()
cursor.execute("SELECT id, ip FROM schema.table;")
rows = cursor.fetchall()
cursor.close()
conn.commit()
conn.close()

This is called in the run() method of a Thread, several times in a while(True) loop. I'm just opening a connection to my PostgreSQL database using the psycopg2 driver.

Any idea of how safe is opening db connections into Threads in Python? I don't know what is raising this error.

2 Answers

The cause of this issue could be, there were too many processes(multi) were trying to access PostGres, it was not able to handle that. I was using Django & PostGres in BeanStalk.

Adding 'OPTIONS': {'sslmode': 'disable'} in the database config helped.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': ...
        'USER': ....
        'PASSWORD': ...
        'HOST': ....
        'PORT': '5432',
        'OPTIONS': {
           'sslmode': 'disable',
        }
    }
}
Related