zlib解压缩标头检查错误

时间:2011-03-11 22:30:46

标签: python postgresql zlib

我有一个字典的问题我正在压缩并存储到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

打开任何关于为什么这会在数据库中搞砸的建议。我应该注意存储值的字段类型是bytea

类型

提前致谢!