D
D
DmitryDA2021-09-27 18:25:46
Python
DmitryDA, 2021-09-27 18:25:46

Library pyTelegramBotAPI-4.1.0.tar. What can be wrong?

The bot has recently stopped working. The error is:
__init__.py:653 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned an invalid JSON response. Response body:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DmitryDA, 2021-09-27
@DmitryDA

import config
from subprocess import check_output
import telebot
from telebot import types
import time
counter = 0
bot = telebot.TeleBot(1474977596:AAE7QdB8CqqFP_dQ5zwtVC6Ymu1DT1gHv5g)#Bot Tokenf
user_id = config.admin #your account
id @bot.message_handler(func=lambda message: True , content_types=['text'])
def send_text(message):
global counter
if user_id == message.chat.id:
if message.text == 'Openwrt on':
counter = 1
bot.send_message(message.chat.id , 'Openwrt console enabled')
elif message.text == 'Openwrt off':
counter = 0
bot.send_message(message.chat.id, 'Openwrt console disabled')
elif (counter == 1):
comand = message.text #message text
try: #if the command is not executable, check_output will throw an exception
bot.send_message(message.chat .id, check_output(comand, shell = True))
except:
bot.send_message(message.chat.id, "Invalid input") #if the command is invalid
Simple example https://habr.com/en/post/443846/
if __name__ == '__main__':
while True:
try:#add try for smooth operation
bot.polling(none_stop=True)#start bot
except:
time.sleep(10)#in case of fall

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question