简体   繁体   English

UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 1551 中的字节 0x87:起始字节无效

[英]UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 1551: invalid start byte

I m trying check Wifi password program on Python so I encounter some problem about unicodeDecodeError I couldn't understand我正在尝试在 Python 上检查 Wifi 密码程序,所以我遇到了一些关于 unicodeDecodeError 的问题,我无法理解

Here is my uptading terminal:这是我的更新终端:

C:\Users\bartu\Desktop\Python\pythonSmallProject>python check_wifi_password.py
Traceback (most recent call last):
  File "check_wifi_password.py", line 10, in <module>
    data = subprocess.check_output(['netsh','wlan','show','profiles']).decode(get_encoding).split('\n') # now we will store the profiles data in the "data" variable by
TypeError: decode() argument 'encoding' must be str,  not function

here is my uptading code:这是我的更新代码:

import subprocess   # first we will import the subprocess module
import os
from chardet import detect

def get_encoding(file):
    with open(file,'rb') as f:
        data = f.read()
    return detect(data)['encoding']

data = subprocess.check_output(['netsh','wlan','show','profiles']).decode(get_encoding).split('\n') # now we will store the profiles data in the "data" variable by
                                                                                               # running the 1st cmd command using subprocess.check_output
profiles =  [i.split(":")[1][1:-1] for i in data  if "All User Profile" in i]  # now we will store the profile by converting them to list

# using  for loop in python we re checking and printing the Wifi
# passwords  if they  are avaiable using the 2nd cmd command
for i in profiles:
    # running the 2nd cmd command to check  passwords
    results = subprocess.check_output(['netsh','wlan','show','profile',i,'key = clear']).decode(get_encoding).split('\n')
    # storing passwords after converting them to list
    results = [j.split(":")[1][1:-1]  for j in results if " Key Content" in j]
    # printing the profiles(wifi name) with their passwords using
    # try and except
try:
    print("{:<30} | {:<}".format(i,results[0]))
except IndexError:
    print("{:<30} | {:<}".format(i, ""))
except subprocess.CalledProcessError:
    print("{:<30} | {:<}".format(i, "ENCODING ERROR"))
print("")

Have you tried using latin encoding?您是否尝试过使用latin编码?

data = subprocess.check_output(['netsh','wlan','show','profiles']).decode('latin1').split('\n')

If it doesn't work, try getting the encoding from the file-如果它不起作用,请尝试从文件中获取编码-

import os    
from chardet import detect

def get_encoding(data):
    return detect(data)['encoding']

data = subprocess.check_output(['netsh','wlan','show','profiles'])
data_encoding = get_encoding(data)
decoded_data = data.decode(data_encoding).split('\n')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PyInstaller:UnicodeDecodeError:&#39;utf-8&#39;编解码器无法解码位置 112 中的字节 0x87:起始字节无效 - PyInstaller: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 112: invalid start byte 解码 TCP 连接的有效负载:“utf-8”编解码器无法解码位置 4 中的字节 0x87:无效起始字节 - Decode Payload of TCP connection: 'utf-8' codec can't decode byte 0x87 in position 4: invalid start byte UnicodeDecodeError:&#39;utf-8&#39;编解码器无法解码位置0的字节0x99:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte UnicodeDecodeError&#39;utf-8&#39;编解码器无法解码位置2893中的字节0x92:无效的起始字节 - UnicodeDecodeError 'utf-8' codec can't decode byte 0x92 in position 2893: invalid start byte Python:UnicodeDecodeError:'utf-8'编解码器无法解码 position 中的字节 0x80 0:无效起始字节 - Python: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte UnicodeDecodeError:“utf-8”编解码器无法解码 position 35 中的字节 0x96:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 35: invalid start byte UnicodeDecodeError: &#39;utf-8&#39; 编解码器无法解码位置 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:&#39;utf-8&#39;编解码器无法解码位置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