2

我正在开发一个 Py3k 程序,我希望能够接受 Unicode 字符串并腌制/解开它们。

但是,它默认为 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

4

1 回答 1

0

I would try and explicitly pass a unicode object to pickle.dump(), something like pickle.dump(unicode(state), output_file)

于 2013-05-13T15:06:15.217 回答