The Python Oracle

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

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Darkness Approaches Looping

--

Chapters
00:00 Python: Decryption Failed Or Bad Record Mac When Calling From Thread
00:31 Accepted Answer Score 6
00:55 Answer 2 Score 0
01:18 Thank you

--

Full question
https://stackoverflow.com/questions/2066...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #multithreading #postgresql #encryption #databaseconnection

#avk47



ACCEPTED ANSWER

Score 6


Ok, looks like I've fixed the problem. I was creating too many connections and seems I was running out of memory or something. I gathered all the queries and do cursor.execute(...) once with a huge query, instead performing hundreds of small queries/connections.

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



ANSWER 2

Score 0


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',
        }
    }
}