Python Forum
maybe you could tell me why my script stops
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
maybe you could tell me why my script stops
#4
i m so sorry guys... i made a copy from linux terminal and copied bad... i update the post

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?
Reply


Messages In This Thread
RE: maybe you could tell me why my script stops - by komarek - Apr-11-2017, 02:28 PM
unfortunately i keep having issues - by komarek - Apr-11-2017, 05:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pip stops waiting for python walker 6 1,342 Nov-28-2023, 06:55 PM
Last Post: walker
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 1,060 Nov-16-2022, 07:58 PM
Last Post: Winfried
  Know when the pyttsx3 engine stops talking UsualCoder 3 3,465 Aug-29-2021, 11:08 PM
Last Post: snippsat
  IDLE stops responding upon saving tompi1 2 2,069 Oct-01-2020, 05:44 PM
Last Post: Larz60+
  Python timer script stops before should ozstar 3 2,350 May-04-2020, 12:55 AM
Last Post: ozstar
  Python stops without errors shahgourav 4 2,922 Feb-04-2020, 11:44 PM
Last Post: micseydel
  First for loop stops after first iteration Divanova94 10 9,356 May-01-2019, 04:27 PM
Last Post: buran
  Python Thread stops execution neethuvp 1 3,517 Feb-18-2019, 06:36 PM
Last Post: micseydel
  randint stops changing values in a loop Naito 4 3,500 Jan-30-2019, 08:15 AM
Last Post: perfringo
  detect when scanner stops darter 1 2,505 Jun-29-2018, 10:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020