i m so sorry guys... i made a copy from linux terminal and copied bad... i update the post
this is actually the code
but once in a day or 2 it breaks with the error i wrote
thanks
this is actually the code
#!/usr/bin/env python3 import os import paho.mqtt.publish as publish import paho.mqtt.client as mqtt import time import smtplib import requests from datetime import datetime def inviamail(sogg, dest, testo): fromaddr = '[email protected]' toaddrs = dest msg = testo sub = sogg username = '[email protected]' password = 'xxxxx' server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() server.login(username,password) message = 'Subject: {}\n\n{}'.format(sub, msg) server.sendmail(fromaddr, toaddrs, message) server.quit() return while True: def on_connect(client, userdata, flags, rc): #print("Connected with result code "+str(rc)) client.subscribe("cancello") def on_message(client, userdata, msg): messaggio = str(msg.payload) if "APERTO" in messaggio: t = datetime.now().time() tempo = str(t)[0:8] print(tempo+" - ACCESSO") inviamail("Cancello Aperto", "[email protected]", "Appena aperto il cancello\nalle ore " + tempo) client.disconnect() client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("127.0.0.1",1883,60) client.loop_forever()the code works fine
but once in a day or 2 it breaks with the error i wrote
thanks
(Apr-11-2017, 01:10 PM)zivoni Wrote: try to replace it with
server = smtplib.SMTP('smtp.gmail.com', 587)i've changed this line.. the script still works... let's see if it gonna break again.thanks
bytheway: if i want to run the script in background at startup in my raspberry how do you suggest me to do that?
shall i write down some error management in the script?