python中的酸洗错误? [英] pickling error in python?
问题描述
我收到此错误,但我不知道这意味着什么.我该如何解决这个问题?
I am getting this error, and I dont know what it means. How can I fix this problem?
我的代码看起来像这样,我以前用过它并且一直有效:
my code looks like this, I've used it before and it has worked:
parentdir = os.getcwd()
dirlist = os.listdir(parentdir)
for dir in dirlist:
if not dir == "pubs_edits": continue
if os.path.isdir(os.path.join(parentdir, dir)):
os.chdir(os.path.join(parentdir, dir))
file_list = os.listdir(os.path.join(parentdir, dir))
for f in file_list:
in1 = open(f, 'r')
dict2 = pickle.load(in1)
这是错误消息:
File "/home/md202/pmid_editor.py", line 18, in <module>
dict2 = pickle.load(in1)
File "/usr/lib/python2.5/pickle.py", line 1370, in load
return Unpickler(file).load()
File "/usr/lib/python2.5/pickle.py", line 858, in load
dispatch[key](self)
KeyError: '\x00'
推荐答案
当我尝试解开(使用pickle.loads)通过django存储在数据库中的字符串表示形式时,对我来说发生了这个确切的错误. Django更改了我的字符串的charactee表示形式,以便pickle.loads(mystring)
抛出该错误.当我在其中添加显式字符串转换时,这很好:pickle.loads( str(mystring) )
This exact error occurred for me when I tried to unpickle (using pickle.loads) a string representation that I had stored in a database via django. Django changed the charactee representation of my string so that pickle.loads(mystring)
threw me that error. When I added an explicit string conversion in, it was fine: pickle.loads( str(mystring) )
查看原始文章的评论,我认为这与提到的unicode字符串问题有关.我将一个普通的字符串放入数据库中,并且django给了我一个产生此错误的unicode字符串.
looking at the comments on the original post, I think this is related to the unicode string issue mentioned. I put a normal string into the database, and django gives me back a unicode string that produces this error.
这篇关于python中的酸洗错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!