utf-8'编解码器无法解码字节 0x8d

发布于 2025-01-18 03:09:44 字数 1678 浏览 1 评论 0原文

由于我是Python新手,所以我在网上看了一个教程。我理解了代码并想在我自己的计算机上运行它。但我遇到了这个错误。

import subprocess

import re

command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()

profile_names = (re.findall("All User Profile     : (.*)\r", command_output))

wifi_list = []

if len(profile_names) != 0:
    for name in profile_names:
        
        wifi_profile = {}
        
        profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode()
        
        if re.search("Security key           : Absent", profile_info):
            continue
        else:
            
            wifi_profile["ssid"] = name
            
            profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode()
            
            password = re.search("Key Content            : (.*)\r", profile_info_pass)
            
            if password == None:
                wifi_profile["password"] = None
            else:
                
                wifi_profile["password"] = password[1]
            
            wifi_list.append(wifi_profile) 

for x in range(len(wifi_list)):
    print(wifi_list[x]) 

给出这样的错误。虽然我稍微理解了这个错误。我不知道该怎么做。就像我说的,我对 python 和编程相当陌生。

Traceback (most recent call last):
  File "C:\Users\ASUS\Desktop\wifi_passwords.py", line 27, in <module>
    command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8d in position 599: invalid start byte

Since I'm new to python, I watched a tutorial on the internet. I understood the code and wanted to run it on my own computer. But I encountered this error.

import subprocess

import re

command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()

profile_names = (re.findall("All User Profile     : (.*)\r", command_output))

wifi_list = []

if len(profile_names) != 0:
    for name in profile_names:
        
        wifi_profile = {}
        
        profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode()
        
        if re.search("Security key           : Absent", profile_info):
            continue
        else:
            
            wifi_profile["ssid"] = name
            
            profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode()
            
            password = re.search("Key Content            : (.*)\r", profile_info_pass)
            
            if password == None:
                wifi_profile["password"] = None
            else:
                
                wifi_profile["password"] = password[1]
            
            wifi_list.append(wifi_profile) 

for x in range(len(wifi_list)):
    print(wifi_list[x]) 

Giving error like that. Although I understand the error a little. I don't know how to do that. Like I said, I'm fairly new to python and programming.

Traceback (most recent call last):
  File "C:\Users\ASUS\Desktop\wifi_passwords.py", line 27, in <module>
    command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8d in position 599: invalid start byte

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文