我有这个代码:
def __executeCommand(self, command: str, input: str = None) -> str:
p = sub.Popen(command, stdout=sub.PIPE, stderr=sub.PIPE, stdin=sub.PIPE, universal_newlines=True)
p.stdin.write(input)
output, error = p.communicate()
if (len(errors) > 0):
raise EnvironmentError("Could not generate the key: " + error)
elif (p.returncode != 0):
raise EnvironmentError("Could not generate the key. Return Value: " + p.returncode)
return output
我在该行中收到 UnicodeDecodeErroroutput, error = p.communicate()
:
Traceback (most recent call last):
File "C:\Python34\lib\threading.py", line 921, in _bootstrap_inner
self.run()
File "C:\Python34\lib\threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "C:\Python34\lib\subprocess.py", line 1170, in _readerthread
buffer.append(fh.read())
File "C:\Python34\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 27: character maps to <undefined>
我怎样才能解决这个问题?