问题描述
ids = cPickle.loads(gem.value)
loads() argument 1 must be string, not unicode
推荐答案
cPickle.loads
想要一个字节字符串(正是cPickle.dumps
输出的),而您却向它提供了一个unicode字符串.您需要对该Unicode字符串进行编码",以获取dumps
最初给您的字节字符串,但是很难猜测您不小心对它施加了什么编码-可能是latin-1
或utf-8
(如果ascii
不用担心,这两个都可以很好地解码),也许utf-16
...?不知道gem
是什么,以及如何根据cPickle.dumps
...!
cPickle.loads
wants a byte string (which is exactly what cPickle.dumps
outputs) and you're feeding it a unicode string instead. You'll need to "encode" that Unicode string to get back the byte string that dumps
had originally given you, but it's hard to guess what encoding you accidentally imposed on it -- maybe latin-1
or utf-8
(if ascii
don't worry, either of those two will decode it just great), maybe utf-16
...? It's hard to guess without knowing what gem
is and how you originally set its value
from the output of a cPickle.dumps
...!
这篇关于如何解决Python中的unicode/cPickle错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!