Discuss / Python / utf-8不能解码oxc8

utf-8不能解码oxc8

Topic source

import subprocess

print('$ nslookup') p = subprocess.Popen(['nslookup'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = p.communicate(b'set q=mx\npython.org\nexit\n') print(output.decode('utf-8')) print('Exit code:', p.returncode)

异常栈: Traceback (most recent call last): File "new.py", line 6, in <module> print(output.decode('utf-8')) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 54: invalid continuation byte

Zh小厨

#2 Created at ... [Delete] [Delete and Lock User]

'utf-8' 改成 'gbk' 就正常了,具体分析可以参考:https://segmentfault.com/q/1010000004268196/a-1020000004269556


  • 1

Reply