我在此代码片段中收到“解密失败或错误记录mac”错误:
conn = psycopg2.connect(...)
cursor = conn.cursor()
cursor.execute("SELECT id, ip FROM schema.table;")
rows = cursor.fetchall()
cursor.close()
conn.commit()
conn.close()
这在Thread的run()方法中调用,在while(True)循环中多次调用。 我只是使用psycopg2驱动程序打开与PostgreSQL数据库的连接。
在Python中打开数据线连接到线程的安全性是什么? 我不知道是什么引起了这个错误。
答案 0 :(得分:5)
好的,看起来我已经解决了这个问题。我创建了太多的连接,似乎我的内存不足或什么的。 我收集了所有查询,并使用一个巨大的查询执行了cursor.execute(...)一次,而不是执行数百个小查询/连接。
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
答案 1 :(得分:0)
此问题的原因可能是,尝试访问PostGres的进程过多(多个),但无法处理。我在BeanStalk中使用Django和PostGres。
在数据库配置中添加'OPTIONS': {'sslmode': 'disable'}
很有帮助。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': ...
'USER': ....
'PASSWORD': ...
'HOST': ....
'PORT': '5432',
'OPTIONS': {
'sslmode': 'disable',
}
}
}