0

Когда передаю два слова в функцию происходит ошибка(находится ниже), если же одно слово, то ошибки не происходит. В чём может быть проблема? Вот ошибка:

2020-08-02 10:50:42,507 (util.py:68 WorkerThread1) ERROR - TeleBot: "ApiException occurred, args=('A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:\n[b\'{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}\']',)
Traceback (most recent call last):
  File "C:\Users\Stepan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "C:/Users/Stepan/Desktop/stslinvestbot.py", line 164, in get_text_messages
    token_bot.send_message(message.chat.id, other_stock(message))
  File "C:\Users\Stepan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 624, in send_message
    apihelper.send_message(self.token, chat_id, text, disable_web_page_preview, reply_to_message_id,
  File "C:\Users\Stepan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 159, in send_message
    return _make_request(token, method_url, params=payload, method='post')
  File "C:\Users\Stepan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 65, in _make_request
    return _check_result(method_name, result)['result']
  File "C:\Users\Stepan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 84, in _check_result
    raise ApiException(msg, method_name, result)
telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}']
"
2020-08-02 10:50:42,508 (__init__.py:443 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}']"

Вот код:

def other_stock(message):  # другая акция
    line_words = message.text.split()
    if len(line_words) == 2:
        ticker = line_words[1]
    else:
        ticker = message.text
    instr = client_invest.market.market_search_by_ticker_get_with_http_info(ticker)
    if ticker == "Назад":
        token_bot.send_message(message.from_user.id, "Хорошо, назад.", reply_markup=user_markup)
        token_bot.register_next_step_handler(message, get_text_messages)
    elif str(instr[0].payload.instruments) == "[]":
        msg = token_bot.send_message(message.chat.id, 'Ошибка! Такой тикер не найден!\nВведите другой тикер:')
        token_bot.register_next_step_handler(msg, other_stock)
        return
    if str(instr[0].payload.instruments) != "[]" and ticker != "Назад":
        token_bot.send_message(message.from_user.id, data_stock(ticker), reply_markup=user_markup)

1 ответ 1

1

У вас ошибка в token_bot.send_message(message.chat.id, other_stock(message)). Судя по вашей функции other_stock она сама отправляет сообщения и ничего не возвращает в ответ. Выглядит это как token_bot.send_message(message.chat.id, None) по итогу. Попробуйте вместо token_bot.send_message(message.chat.id, other_stock(message)) вызвать просто other_stock(message).

1
  • Да работает теперь верно, спасибо. 2 авг 2020 в 9:03

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.