简体   繁体   English

UnicodeDecodeError:“utf-8”编解码器无法解码 position 76 中的字节 0x81:起始字节无效

[英]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.

相关问题 Python 错误:UnicodeDecodeError:“utf-8”编解码器无法解码 position 中的字节 0x81 76:起始字节无效 - Python Error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 76: invalid start byte pandas csv UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 162: invalid start byte - pandas csv UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 162: invalid start byte 如何修复:UnicodeDecodeError:“utf-8”编解码器无法解码 position 中的字节 0x81 18:起始字节无效 - How to fix: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 18: invalid start byte UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0x80:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 1072 中的字节 0x95:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x95 in position 1072: invalid start byte UnicodeDecodeError:“utf-8”编解码器无法解码位置 1 的字节 0x8b:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 3131 中的字节 0x80:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte Python UnicodeDecodeError:“ utf-8”编解码器无法解码位置2的字节0x8c:无效的起始字节 - Python UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8c in position 2: invalid start byte UnicodeDecodeError:'utf-8'编解码器无法解码位置3的字节0x97:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 3: invalid start byte `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte` - `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM