на серваке пробовал запускать через screen dmS и просто через venv + py3 в чем может быть проблема? при отправке любой команды получаю invalid input УПД ось armbian from subprocess import check_output import telebot from telebot import types import time bot = telebot.TeleBot("снес") user_id = #снес @bot.message_handler(content_types=["text"]) def main(message): if (user_id == message.chat.id): comand = message.text markup = types.InlineKeyboardMarkup() button = types.InlineKeyboardButton(text="re", callback_data=comand) markup.add(button) try: bot.send_message(user_id, check_output(comand, shell = True, reply_markup = markup)) except: bot.send_message(user_id, "Invalid input") @bot.callback_query_handler(func=lambda call: True) def callback(call): comand = call.data try: markup = types.InlineKeyboardMarkup() button = types.InlineKeyboardButton(text="re", callback_data=comand) markup.add(button) bot.send_message(user_id, check_output(comand, shell = True), reply_markup = markup) except: bot.send_message(user_id, "Invalid input") if __name__ == '__main__': while True: try: bot.polling(none_stop=True) except: time.sleep(10) Python from subprocess import check_output import telebot from telebot import types import time bot = telebot.TeleBot("снес") user_id = #снес @bot.message_handler(content_types=["text"]) def main(message): if (user_id == message.chat.id): comand = message.text markup = types.InlineKeyboardMarkup() button = types.InlineKeyboardButton(text="re", callback_data=comand) markup.add(button) try: bot.send_message(user_id, check_output(comand, shell = True, reply_markup = markup)) except: bot.send_message(user_id, "Invalid input") @bot.callback_query_handler(func=lambda call: True) def callback(call): comand = call.data try: markup = types.InlineKeyboardMarkup() button = types.InlineKeyboardButton(text="re", callback_data=comand) markup.add(button) bot.send_message(user_id, check_output(comand, shell = True), reply_markup = markup) except: bot.send_message(user_id, "Invalid input") if __name__ == '__main__': while True: try: bot.polling(none_stop=True) except: time.sleep(10)
Eternusta, привет! Возможно, проблема в том, что ты не указал полный путь к исполняемому файлу, который ты пытаешься запустить. Попробуй добавить полный путь к файлу в команду, например: bot.send_message(user_id, check_output('/полный/путь/к/файлу ' + comand, shell=True, reply_markup=markup)) Код bot.send_message(user_id, check_output('/полный/путь/к/файлу ' + comand, shell=True, reply_markup=markup)) Также, убедись, что ты запускаешь команду от имени пользователя, который имеет достаточные права на выполнение этой команды.
Eternusta, спасибо за скриншот. Кажется, проблема может быть связана с тем, что ты используешь функцию `check_output` из модуля `subprocess`, которая возвращает вывод команды в виде байтовой строки. Попробуй использовать метод `decode()` для преобразования байтовой строки в обычную строку, например: bot.send_message(user_id, check_output(comand, shell=True).decode(), reply_markup=markup) Python bot.send_message(user_id, check_output(comand, shell=True).decode(), reply_markup=markup) Также, убедись, что ты используешь правильный синтаксис для команды, которую ты пытаешься выполнить. Если возможно, попробуй выполнить эту команду вручную на сервере, чтобы убедиться, что она работает правильно.
Eternusta, рад, что проблема была найдена! Если у тебя возникнут еще какие-либо вопросы, не стесняйся задавать их здесь. Я всегда готов помочь.
ну так ты exception обработай, да глянь че там except Exception as err: bot.send_message(user_id, f"Invalid input: {err}") Python except Exception as err: bot.send_message(user_id, f"Invalid input: {err}")