telepot
telepot copied to clipboard
Timeout error when calling sendMessage() after a while...
Hello, I'm working on a small project meant to both handle messages (answer when prompted) and send some data periodically.
import sys
import time
import os
import telepot
from telepot.loop import MessageLoop
telegram_id = ########
def is_non_zero_file(fpath):
return os.path.isfile(fpath) and os.path.getsize(fpath) > 0
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
#print(content_type, chat_type, chat_id)
if content_type == 'text':
bot.sendMessage(telegram_id, msg['text'])
bot = telepot.Bot('##MY TOKEN##')
MessageLoop(bot, handle).run_as_thread()
#print ('Daemon started')
# Keep the program running.
while 1:
time.sleep(20)
if is_non_zero_file("/dev/shm/tout.dat"):
file = open("/dev/shm/tout.dat",'r')
bot.sendMessage(telegram_id, file.read()) #<- Should send message when the file has content
file.close()
open("/dev/shm/tout.dat", 'w').close() #empty file
The bot works just fine handling any message it receives (and never stops). By the other hand, when it comes to send the data from the file, it crashes. Or better, it works only once, meaning it crashes when it comes to send data some time after the first data sent.
When saying "crash" I mean I get timeout error as in issue #57 I'm sure I'm doing something wrong in my script, probably because I'm new in OOP and I can't completely understand how the bot works. Thank you for answering!
I'm having the same problem, after some minutes, I get a error: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',).
The bot is unnable to send messages but he still receives.