我在打电话 pipe.communicate
来自Python的 subprocess
Python 2.6中的模块。我从这段代码中得到以下错误:
from subprocess import Popen
pipe = Popen(cwd)
pipe.communicate( data )
对于任意的 cwd
,以及在哪里 data
包含unicode(特别是0xE9):
Exec. exception: 'ascii' codec can't encode character u'\xe9' in position 507: ordinal not in range(128)
Traceback (most recent call last):
... stdout, stderr = pipe.communicate( data )
File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py",
line 671, in communicate
return self._communicate(input)
File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py",
line 1177, in _communicate
bytes_written = os.write(self.stdin.fileno(), chunk)
我猜想,这种情况正在发生,因为 pipe.communicate()
期待ASCII编码的字符串,但是 data
是unicode。
这是我遇到的问题,我有办法将unicode传递给 pipe.communicate()
?
谢谢你的阅读!
布赖恩