代码:
import os
ipconfig1 = os.popen("ipconfig /all")
ipconfig2 = ipconfig1.read()
ipconfig
输出具有非拉丁符号。错误:
Traceback (most recent call last):
File "getIt.py", line 4, in <module>
ipconfig2 = ipconfig1.read()
File "C:\Program Files (x86)\Python37-32\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 2948: character maps to <undefined>
我尝试过的事情:
pip install win-unicode-console
并且(是的,其中之一很愚蠢,但我拼命尝试了)
ipconfig2 = ipconfig1.decode('utf8').read()
ipconfig2 = ipconfig1.encode('utf8').read()
在bat文件中:chcp 65001
,set PYTHONIOENCODING=:replace
和set PYTHONIOENCODING=utf-8
这些都不起作用。如何正确执行?