[英]UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 76: invalid start byte
I want to create a program that decodes wifi passwords.我想创建一个解码 wifi 密码的程序。 I am not finished yet, but the program should print the names of all wifis.
我还没有完成,但程序应该打印所有 wifis 的名称。 But there is this error and I don't know how to fix it.
但是有这个错误,我不知道如何解决。
import subprocess
data = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("utf-8").split("\n")
wifis = [line.split(":")(1)[1:-1] for line in data if "All User Profile" in line]
print (data)
Error:错误:
data = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("utf-8").split()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 76: invalid start byte
netsh
is a hint that you are using a Windows system. netsh
提示您正在使用 Windows 系统。 The console applications often use cp850 encoding for West European languages.控制台应用程序通常对西欧语言使用 cp850 编码。 So you could try:
所以你可以尝试:
data = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("cp850").split("\n")
Or to be safe you can use an encoding able to accept any input byte like latin1 but it seldom returns the expected characters on Windows. But NEVER use utf-8
when the input is not utf-8 encoded.或者为了安全起见,您可以使用能够接受任何输入字节的编码,如 latin1,但它很少返回 Windows 上的预期字符。但是当输入不是 utf-8 编码时,切勿使用
utf-8
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.