我想使用 pythons pickle 和管道通过 ssh 中的管道发送一个 unicode 字符串:
import subprocess
import pickle
cmd=['ssh', 'user@host', '/usr/bin/env', 'python3', '-c', \
'"import sys;import pickle;import os;os.mkdir(pickle.Unpickler(sys.stdin).load())"']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
pickler = pickle.Pickler(p.stdin)
pickler.dump('äöü')
这会产生以下错误:
>>> Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)
我还注意到发送到子进程的 unicode 字符没有正确显示,相反我只看到它们的十六进制表示。有谁知道问题是什么以及如何解决这个问题?