TypeError:不能在未获取条件的对象regex之类的字节上使用字符串模式



我正在尝试使用regex进行筛选,它显示TypeError: cannot use a string pattern on a bytes-like object.我不知道为什么,但我认为它没有正确注册我的标准,这里是代码。


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 = re.search(":Profiles*:s(.*)", networks )
print(network_names.group(0))

subprocess.check_output返回字节字符串(类型为bytes(,而不是Unicode字符串(类型str(。要在字节字符串上使用re.search,请为表达式使用字节字符串:

network_names = re.search(b":Profiles*:s(.*)", networks )
^
Note!

最新更新