Ich rufe pipe.communicate
von Python subprocess
-Modul von Python 2.6. Ich erhalte den folgenden Fehler aus diesem Code:Python-Codierung für pipe.communicate
from subprocess import Popen
pipe = Popen(cwd)
pipe.communicate(data)
Für eine beliebige cwd
, und wo data
, die auf Unicode (speziell 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)
Dies geschieht, nehme ich an, weil pipe.communicate()
erwartet ASCII-codierte Zeichenfolge, aber data
ist Unicode.
Ist das das Problem, auf das ich stoße, und ich einen Weg, Unicode an pipe.communicate()
zu übergeben?
Vielen Dank für das Lesen!
Brian
Was meinen Sie mit "enthält Unicode"? Insbesondere ist 0xE9 an sich kein gültiger Unicode-Codepunkt in einer gängigen Codierung. – tripleee