J'appelle pipe.communicate
depuis le module Python subprocess
de Python 2.6. Je reçois l'erreur suivante de ce code:Codage Python pour pipe.communicate
from subprocess import Popen
pipe = Popen(cwd)
pipe.communicate(data)
Pour un cwd
arbitraire, et où data
qui contient unicode (en particulier 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)
Ce qui se passe, je présume, parce que pipe.communicate()
attend Chaîne codée ASCII, mais data
est unicode.
Est-ce le problème que je rencontre, et je trouve un moyen de passer unicode à pipe.communicate()
?
Merci d'avoir lu!
Brian
Que voulez-vous dire par "contient Unicode"? Plus précisément, 0xE9 n'est pas, en soi, un point de code Unicode valide dans un codage commun. – tripleee