@AruxGame

Telegram ошибка HTTP 400?

Ошибка HTTP 400 как исправить или сделать что-бы БОТ игнорировал ошибки и продолжал работать?
Вот код самого БОТА:

import telebot
import config
import requests
from bs4 import BeautifulSoup as BS
import time

bot = telebot.TeleBot(config.token)

@bot.message_handler(content_types=['text'])
def games(message):
    r = requests.get('https://stopgame.ru/review/new/stopchoice')
    html = BS(r.content, 'html.parser')

    for el in html.select('.caption'):
        title = el.select('.caption-bold > a')
        time.sleep(0.4)   # Вот писал Time-Sleep но не помогло.
        bot.send_message(message.chat.id, title)

if __name__ == '__main__':
    bot.polling(none_stop=True)


Вот логи:

2020-08-22 01:36:25,323 (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\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "C:\Users\User\Desktop\My_Info_Bot\check_money.py", line 18, in games
    bot.send_message(message.chat.id, title)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\__init__.py", line 641, in send_message
    reply_markup, parse_mode, disable_notification, timeout))
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\apihelper.py", line 166, in send_message
    return _make_request(token, method_url, params=payload, method='post')
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\apihelper.py", line 69, in _make_request
    return _check_result(method_name, result)['result']
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\apihelper.py", line 88, 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-22 01:36:25,326 (__init__.py:455 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"}']"
  • Вопрос задан
  • 2852 просмотра
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
Может, нужно не игнорировать ошибки, а обрабатывать их?

for el in html.select('.caption'):
        title = el.select('.caption-bold > a')
        if title:
            bot.send_message(message.chat.id, title)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы