Ошибка бота python: telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized
Думал из за блока Апи от телеги: через прокси решил зайти, но выдает ошибку
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
import menu
import settings
import functions as func
import telebot
from telebot import types
from telebot import apihelper
import time
import datetime
import random
import threading
import config
from PIL import Image
import traceback
buy_dict = {}
balance_dict = {}
admin_sending_messages_dict = {}
product_dict = {}
download_dict = {}
def start_bot():
bot = telebot.TeleBot(config.config('bot_token'), threaded=True, num_threads=300)
# Command start
@bot.message_handler(commands=['start'])
def handler_start(message):
chat_id = message.chat.id
resp = func.first_join(user_id=chat_id, name=message.from_user.username, code=message.text[7:])
with open('welcome.jpg', 'rb') as photo:
bot.send_photo(
chat_id=chat_id,
photo=photo,
caption='Добро пожаловать {}!'.format(message.from_user.first_name,),
reply_markup=menu.main_menu()
)
# Command admin
@bot.message_handler(commands=['admin'])
def handler_admin(message):
chat_id = message.chat.id
if str(chat_id) in func.admin_id_manager() or str(chat_id) in func.admin_id_own():
bot.send_message(chat_id, 'Вы перешли в меню админа', reply_markup=menu.admin_menu)
@bot.message_handler(content_types=['text'])
def send_message(message):
if str(message.chat.id) in func.ban():
print('spam')
else:
chat_id = message.chat.id
first_name = message.from_user.first_name
username = message.from_user.username
if message.text in func.btn_menu_list():
conn = sqlite3.connect('base.db')
cursor = conn.cursor()
base = cursor.execute(f'SELECT * FROM buttons WHERE name = "{message.text}"').fetchone()
with open(f'{base[2]}.jpg', 'rb') as photo:
bot.send_photo(
chat_id=chat_id,
photo=photo,
caption=base[1]
)
if message.text == menu.main_menu_btn[0]:
try:
bot.send_message(
chat_id=chat_id,
text=func.info_numbers(chat_id),
reply_markup=func.buy_number_menu()
)
except: pass
if message.text == menu.main_menu_btn[1]:
try:
info = func.profile(chat_id)
msg = settings.profile.format(
id=info[0],
login=f'@{info[1]}',
data=info[2][:19],
balance=info[5]
),
bot.send_message(
chat_id=chat_id,
text=msg)
except Exception as e: pass
if message.text == menu.main_menu_btn[2]:
bot.send_message(
chat_id=chat_id,
text=settings.info,
reply_markup=menu.main_menu(),
parse_mode='html'
)
if message.text == menu.main_menu_btn[3]:
try:
resp = func.replenish_balance(chat_id)
bot.send_message(chat_id=chat_id,
text=resp[0],
reply_markup=resp[1],
parse_mode='html')
except Exception as e: print(f"error: {e}")
if message.text == menu.main_menu_btn[4]:
try:
ref_code = func.check_ref_code(chat_id)
bot.send_message(
chat_id=chat_id,
text=f'? Реферальная сеть\n\n'
f'Ваша реферельная ссылка:\n'
f'https://teleg.run/{config.config("bot_login")}?start={ref_code}\n'
f'https://t.me/{config.config("bot_login")}?start={ref_code}\n\n'
f'За все время вы заработали - {func.check_all_profit_user(chat_id)} ₽\n'
f'Вы пригласили - {func.top_ref_invite(chat_id)} людей\n\n'
f'<i>Если человек приглашенный по вашей реферальной ссылки пополнит баланс, то вы получите {config.config("ref_percent")} % от суммы его депозита</i>',
reply_markup=menu.main_menu(),
parse_mode='html'
)
except Exception as e: print(e)
# Обработка данных
@bot.callback_query_handler(func=lambda call: True)
def handler_call(call):
chat_id = call.message.chat.id
message_id = call.message.message_id
try:
if call.data in ['adds2', 'adds1', 'adds3', 'buy_numbers', 'info', 'profile', 'replenish_balance', 'referral_web']:
bot.send_message(
chat_id=chat_id,
text='У нас новое меню ?',
reply_markup=menu.main_menu()
)
if call.data == 'email_sending':
bot.send_message(
chat_id=chat_id,
text='Выбирите вариант рассылки',
reply_markup=menu.email_sending()
)
if call.data == 'email_sending_photo':
msg = bot.send_message(
chat_id=chat_id,
text='Отправьте фото боту, только фото!',
)
bot.clear_step_handler_by_chat_id(chat_id)
bot.register_next_step_handler(msg, email_sending_photo)
if call.data == 'email_sending_text':
msg = bot.send_message(
chat_id=chat_id,
text='Введите текст рассылки',
)
bot.clear_step_handler_by_chat_id(chat_id)
bot.register_next_step_handler(msg, admin_sending_messages)
if 'get_code_' in call.data:
code = func.get_code(call.data[9:])
if str(code[0]) == 'STATUS_OK':
bot.send_message(
chat_id=chat_id,
text=f'СТАТУС: {code[0]}\n'
f'КОД: <code>{code[1]}</code>',
reply_markup=code[2],
parse_mode='html'
)
else:
bot.send_message(
chat_id=chat_id,
text='Cмс не пришла'
)
if 'buynum_' in call.data:
if func.check_balance(chat_id, func.check_price_number(call.data[7:])) == 1:
info = func.Buy(chat_id)
buy_dict[chat_id] = info
info = buy_dict[chat_id]
info.code = call.data[7:]
try:
info = buy_dict[chat_id]
resp = func.buy_number(info)
if resp[0] == True:
bot.send_message(
chat_id=chat_id,
text=f'Сервис: {func.get_service_name(call.data[7:])}\nВаш номер: {resp[1]}\nОжидайте прихода смс\n\n<i>Если смс не прийдет через 5 мину,введите сюда код`т, то вам вернуться потраченные деньги за этот номер, аренда номера будет отменена!!!</i>',
parse_mode='html'
)