我缺少什么来挑选和取消Unicode

时间:2013-05-13 14:13:27

标签: python unicode python-3.x marshalling unmarshalling

我正在开发一个Py3k程序,我希望能够接受Unicode字符串并对其进行pickle / unpickle。

但是,它默认为ASCII编解码器,并抱怨Unicode错误:

UnicodeEncodeError: 'ascii' codec can't encode character '\u0161' in position 1442: ordinal not in range(128) 
      args = ('ascii', "Content-Type: text/html\n\n<!DOCTYPE html>\n<html>\n...ype='submit'>\n </form>\n </body>\n</html>", 1442, 1443, 'ordinal not in range(128)') 
      encoding = 'ascii' 
      end = 1443 
      object = "Content-Type: text/html\n\n<!DOCTYPE html>\n<html>\n...ype='submit'>\n </form>\n </body>\n</html>" 
      reason = 'ordinal not in range(128)' 
      start = 1442 
      with_traceback = <built-in method with_traceback of UnicodeEncodeError object>

如何更改编解码器或以其他方式更改内容,以便从CGI字符串中获取的Unicode值将成功编组并解组为Unicode字符串?

谢谢,

- 编辑 -

源代码位于http://pastebin.com/nX2w1tqa

1 个答案:

答案 0 :(得分:0)

我会尝试将unicode对象显式传递给pickle.dump(),类似于pickle.dump(unicode(state), output_file)