У меня есть этот скрипт, который отправляет электронное письмо, когда оно удовлетворяет условию.Что не так с кодировкой?Я пытался перезапустить службу несколько раз, но все равно ничего не получилось.
Спасибо за помощь.
from flask import Flask, render_template
from flask_mail import Mail, Message
#other imports
app = Flask(__name__)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'mail@gmail.com' # enter your email here
app.config['MAIL_DEFAULT_SENDER'] = 'mail@gmail.com' # enter your email here
app.config['MAIL_PASSWORD'] = 'password' # enter your password here
mail=Mail(app)
#other parts unnecessary to be posted
@app.route("/")
def tempReading():
t=open(temp_sensor,'r')
lines=t.readlines()
t.close()
dista=subprocess.check_output('sudo python /home/pi/webserver/sonic.py', shell=True)
temp_output = lines[1].find('t=')
if temp_output != -1:
temp_string=lines[1].strip()[temp_output+2:]
temp_c=float(temp_string)/1000.0
elif temp_c>30:
msg=Message("Temperature Warning", recipients['1234567@sms.clicksend.com'])
msg.body="Temperature is ",temp_c
mail.send(msg)
templateData = {
'temp': round(temp_c,1),
'dis': dista
}
return render_template('temp.html',**templateData)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)