H
H
huber0812022-02-04 15:56:20
Python
huber081, 2022-02-04 15:56:20

How to deal with 'utf-8' codec can't decode byte 0x81 in position 0: invalid start byte error?

I watched a video about how to find out the WiFi password using Python on the PythonToday channel. At the same time, I wrote code in PyCharm.

The code:

import subprocess


def extract_wifi_passwords() -> object:
    profiles_date = subprocess.check_output('netsh wlan show profiles').decode('utf-8').split('\n')
    # print(profiles_date)
    #
    # from item in profiles_date
    #    print(item)

    profiles = [i.split(':')[1].strip() for i in profiles_date if 'All User Profile' in i]
    # print(profiles)

    for profile in profiles:
        profile_info = subprocess.check_output(f'netsh wlan show profile {profile} key=clear').decode('utf-8').split('\n')
        # print(profile_info)

        try:
            password = [i/split(':')[1].sprit() for i in profile_info if 'Key Content' in i][1]
        except IndexError:
            password = None

        # print (f'Profiles: {profile}\nPassword: {password}\n{"#" * 20}')

        with open(file='wifi_password.txt', mode='a', encoding='utf-8') as file:
            file.write(f'Profiles: {profile}\nPassword: {password}\n{"#" * 20}\n')


extract_wifi_passwords()


I don't know much about Python, when Run Script displays this - 'utf-8' codec can't decode byte 0x81 in position 0: invalid start byte. Please help me fix this!

Run window:

"C:\PyCharm Projects\WiPassTheft\venv\Scripts\python.exe" "C:/PyCharm Projects/WiPassTheft/wpt.py"
Traceback (most recent call last):
  File "C:\PyCharm Projects\WiPassTheft\wpt.py", line 29, in <module>
    extract_wifi_passwords()
  File "C:\PyCharm Projects\WiPassTheft\wpt.py", line 5, in extract_wifi_passwords
    profiles_date = subprocess.check_output('netsh wlan show profiles').decode('utf-8').split('\n')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 0: invalid start byte

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2022-02-04
@huber081

And how long have we had netsh output encoded in utf-8?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question