Ошибка авторизации в боте
Бот при запуске выдает ошибку
(venv) root@ggprom:~/get_sms_tg_bot# python3 main.py
Traceback (most recent call last):
File "main.py", line 1195, in <module>
start_bot()
File "main.py", line 1038, in start_bot
numberrs_buy(start)
File "main.py", line 954, in numberrs_buy
func.admin_rass(textt)
File "/root/get_sms_tg_bot/functions.py", line 459, in admin_rass
rassilka.send_message(1462109040, user_id)
File "/usr/local/lib/python3.6/dist-packages/telebot/__init__.py", line 735, in send_message
reply_markup, parse_mode, disable_notification, timeout))
File "/usr/local/lib/python3.6/dist-packages/telebot/apihelper.py", line 206, in send_message
return _make_request(token, method_url, params=payload, method='post')
File "/usr/local/lib/python3.6/dist-packages/telebot/apihelper.py", line 113, in _make_request
json_result = _check_result(method_name, result)
File "/usr/local/lib/python3.6/dist-packages/telebot/apihelper.py", line 140, in _check_result
raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized
Из ошибки можно сделать вывод что токен не верный, однако при веб запросе ответ положительный
{"ok":true,"result":{"id":1559818692,"is_bot":true,"first_name":"SMS","username":"get_sms_tg_bot","can_join_groups":true,"can_read_all_group_messages":false,"supports_inline_queries":false}}
Весь код вставить не могу, вот начало и конец
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
import menu
import settings
import functions as func
import telebot
from telebot import types, apihelper
import time
import datetime
import random
import threading
import config
import traceback
buy_dict = {}
balance_dict = {}
admin_sending_messages_dict = {}
product_dict = {}
download_dict = {}
def start_bot():
bot = telebot.TeleBot(token='1559818692:AAGb14vs4vP1SqJ-n9WIABd2QXvs9l8wfRM', threaded=True, num_threads=300)
#apihelper.proxy = {"https": "socks5://178.165.44.122:1080"}
# *тут функции, пропустим лишнее*
threading.Thread(target=sending_check).start()
bot.polling(none_stop=True)
start_bot()
Ответы (1 шт):
Автор решения: Іван Шнір
→ Ссылка
Во-первых, эта строка:
bot = telebot.TeleBot(
token='1559818692:AAGb14vs4vP1SqJn9WIABd2QXvs9l8wfRM',
threaded=True,
num_threads=300)
должна быть глобальной; во-вторых вы должны прописывать bot.polling() вне функции.
Пример:
bot = telebot.TeleBot(
token='1559818692:AAGb14vs4vP1SqJn9WIABd2QXvs9l8wfRM',
threaded=True,
num_threads=300)
--Тут все функции--
bot.polling(none_stop=True)