M
M
mlpprv2018-04-04 10:02:06
Flask
mlpprv, 2018-04-04 10:02:06

Bypass user blocking (Error 403: bot was blocked by the user)?

Actually the problem is how to teach the bot to check if the user is blocked:

[2018-04-04 06:49:09,913] ERROR in app: Exception on / [POST]
2018-04-04 06:49:09,924: Traceback (most recent call last ):
2018-04-04 06:49:09,924: File "/home/Mlpprv/venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2018-04-04 06 :49:09,924: response = self.full_dispatch_request()
2018-04-04 06:49:09,924: File "/home/Mlpprv/venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2018-04-04 06:49:09,924: rv = self.handle_user_exception(e)
2018-04-04 06:49:09,924: File "/home/Mlpprv/venv/lib/python3.6/site -packages/flask/app.py", line 1517, in handle_user_exception
2018-04-04 06:49:09,924: reraise(exc_type, exc_value, tb
) /_compat.py", line 33, in reraise
2018-04-04 06:49:09,924: raise value
2018-04-04 06:49:09,925: File "/home/Mlpprv/venv/lib/python3.6/ site-packages/flask/app.py", line 1612, in full_dispatch_request
2018-04-04 06:49:09,925: rv = self.dispatch_request()
2018-04-04 06:49:09,925: File "/home/ Mlpprv/venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2018-04-04 06:49:09,925: return self.view_functions[rule.endpoint](**req .view_args)
2018-04-04 06:49:09,925: File "/home/Mlpprv/bot/main.py", line 2345, in index
2018-04-04 06:49:09,925: reply_markup=user_markup
) ", line 470, in send_message
2018-04-04 06:49:09,925: reply_markup, parse_mode, disable_notification))
2018-04-04 06:49:09,925: File "/home/Mlpprv/venv/lib/python3.6 /site-packages/telebot/apihelper.py", line 135, in send_message
2018-04-04 06:49:09,925: return _make_request(token, method_url, params=payload, method='post')
2018-04-04 06:49:09,926: File "/home/Mlpprv/venv/lib/python3.6/site-packages/telebot/apihelper.py", line 56, in _make_request
2018-04-04 06:49:09,926: return _check_result (method_name, result)['result']
2018-04-04 06:49:09,926: File "/home/Mlpprv/venv/lib/python3.6/site-packages/telebot/apihelper.py", line 75, in _check_result
2018-04-04 06:49 :09,926: raise ApiException(msg, method_name, result)
2018-04-04 06:49:09,926: telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 403 Forbidden. Response body: 2018-04-04 06:49: 09,926
: [b'{"ok":false,"error_code":403,"description":"Forbidden: bot was blocked by the user"}']

that through try-except
I don’t understand what exactly to write in except to bypass the error
. The bot starts to loop and, as a result, falls and stops responding at all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2018-04-04
@mlpprv

try:
  ...
except telebot.apihelper.ApiException:
  ...

P
Pionchik, 2021-11-12
@Pionchik

After a long search for a solution, the answer turned out to be simple:

try:
# your code here
pass #это просто держатель места, не обязательно его вводить в коде 

except:
# your code here
pass #это просто держатель места, не обязательно его вводить в коде

That is, it is not necessary to enter something in except!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question