zlib解压头检查错误

发布于 2024-10-21 16:55:15 字数 1660 浏览 1 评论 0原文

我正在压缩并存储到 postgres 数据库的字典有问题。我可以毫无错误地压缩字典并解压缩它,但是当我将其插入数据库,然后选择它并尝试解压缩数据时,我收到错误:

zlib.error: Error -3 while decompressing data: incorrect header check

这是我编写的用于模拟所有部分的测试脚本:

import zlib
import cPickle
import psycopg2

try:
    db = psycopg2.connect( database='*****', user='*****', password='*****',host='******')
    cursor = db.cursor()

except:
    print 'no db'

atom_id = 166503
params = {'submission': 'RVBV4SXLVVDNAAKIG2LIJKZQ', 'campaign': 'p3percybot', 'dob': '2011-03-11', 'rndrpath': '/mnt/webservices/store/p3percybot/rndr/2011-03-11/RVBV4SXLVVDNAAKIG2LIJKZQ', 'outpath': '/mnt/webservices/store/p3percybot/out/2011-03-11/RVBV4SXLVVDNAAKIG2LIJKZQ', 'srcpath': '/mnt/webservices/store/p3percybot/src', 'root': '/mnt/webservices/store', 'inpath': '/mnt/webservices/store/p3percybot/in/2011-03-11/RVBV4SXLVVDNAAKIG2LIJKZQ'}

print params
params_list = []
for k in params :
        param_name = k
        param_value = cPickle.dumps(params[k])
        param_value = zlib.compress(param_value,9)
        param_value = buffer(param_value)
        params_list.append((param_value,atom_id, param_name))

print params_list

sql = 'UPDATE atomparams set value = %s where atomid=%s and name=%s'
cursor.executemany(sql, (params_list))

sql = 'SELECT name, value FROM atomparams WHERE atomid=%s'
cursor.execute(sql, (atom_id,))
result = cursor.fetchall()

print '\n-----------------result-----------------'
print result
for data in result:
   print data[0]
   data_string = zlib.decompress(data[1])
   print data_string

Open to any关于为什么这在数据库中变得混乱的建议。我应该注意存储值的字段类型是 bytea 类型

提前致谢!

I have an issue with a dictionary I'm compressing and storing to a postgres database. I can compress the dictionary and decompress it without fault but when I insert it into the database, and then select it back and try to decompress the data I get an error:

zlib.error: Error -3 while decompressing data: incorrect header check

Here's a test script I wrote to emulate all the parts:

import zlib
import cPickle
import psycopg2

try:
    db = psycopg2.connect( database='*****', user='*****', password='*****',host='******')
    cursor = db.cursor()

except:
    print 'no db'

atom_id = 166503
params = {'submission': 'RVBV4SXLVVDNAAKIG2LIJKZQ', 'campaign': 'p3percybot', 'dob': '2011-03-11', 'rndrpath': '/mnt/webservices/store/p3percybot/rndr/2011-03-11/RVBV4SXLVVDNAAKIG2LIJKZQ', 'outpath': '/mnt/webservices/store/p3percybot/out/2011-03-11/RVBV4SXLVVDNAAKIG2LIJKZQ', 'srcpath': '/mnt/webservices/store/p3percybot/src', 'root': '/mnt/webservices/store', 'inpath': '/mnt/webservices/store/p3percybot/in/2011-03-11/RVBV4SXLVVDNAAKIG2LIJKZQ'}

print params
params_list = []
for k in params :
        param_name = k
        param_value = cPickle.dumps(params[k])
        param_value = zlib.compress(param_value,9)
        param_value = buffer(param_value)
        params_list.append((param_value,atom_id, param_name))

print params_list

sql = 'UPDATE atomparams set value = %s where atomid=%s and name=%s'
cursor.executemany(sql, (params_list))

sql = 'SELECT name, value FROM atomparams WHERE atomid=%s'
cursor.execute(sql, (atom_id,))
result = cursor.fetchall()

print '\n-----------------result-----------------'
print result
for data in result:
   print data[0]
   data_string = zlib.decompress(data[1])
   print data_string

Open to any suggestions as to why this is getting messed up in the db. I should note the field type storing the value is of type bytea

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文