nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.43k stars 475 forks source link

Timeout error when calling sendMessage() after a while... #379

Open Yaxit opened 6 years ago

Yaxit commented 6 years ago

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!

milteven12 commented 6 years ago

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.