我试图制作一个脚本,允许用户通过gmail发送文件的内容。你知道吗
这是我的密码:
if input1 == 'mail':
path = input("open -- ")
with open(path, "r") as file:
addr = os.environ.get("email")
pw = os.environ.get("pass")
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(addr, pw)
reading = file.read()
subject = path
body = reading
msg = f'Subject {subject}\n\n{body}'
input3 = ('recipient -- ')
server.sendmail(email, input3, msg)'
它给了我一个错误:
File "C:/Users/Whit/PycharmProjects/rps/venv/Scripts/maxnum.py", line 36, in <module>
server.login(addr, pw)
File "C:\Users\Whit\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "C:\Users\Whit\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 638, in auth
authobject(challenge).encode('ascii'), eol='')
AttributeError: 'NoneType' object has no attribute 'encode'
您提供给
smtplib
的某些值是None
。最有可能的情况是,我得到了对getent
的一个或两个调用的结果。你知道吗如果未设置
email
或pass
环境变量,您的程序将执行什么操作?在继续之前,您可能应该检查getent
的结果。你知道吗相关问题 更多 >
编程相关推荐