A
A
AruxGame2020-08-22 01:39:40
Python
AruxGame, 2020-08-22 01:39:40

Telegram HTTP 400 error?

HTTP 400 error how to fix or do something so that the BOT ignores errors and continues to work?
Here is the code for the bot itself:

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)


Here are the logs:

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"}']"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-22
@AruxGame

Maybe you should not ignore errors, but handle them?

for el in html.select('.caption'):
        title = el.select('.caption-bold > a')
        if title:
            bot.send_message(message.chat.id, title)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question