проблемы с прокси и интерактивной кнопкой

a-rooot

Новичок
Пользователь
Май 4, 2020
3
1
3
Windows 7(x64)
Python 3.8.2
PyCharm 2019

Начал изучать Python. Создал бота в Телеграм. Добавил интерактивные кнопки, но при выборе кнопки "4" выдает ошибку:
markup.add('1', '2', '3', '4' )
AttributeError: 'NoneType' object has no attribute 'add'
Как возможно исправить?

И проблема в прокси. Нахожусь в России. приобрел прокси, ввел данные в Телеграм, и этот же прокси в apihelper, но вылетает ошибка: SOCKSHTTPSConnectionPool(host='api.telegram.org', port=443)
при замене прокси в PyCharm ошибка временно решается, но хотелось бы узнать как устранить проблему.

Python:
import telebot
from telebot import types
from telebot import apihelper

bot = telebot.TeleBot('token')
apihelper.proxy = {"https": "socks5://proxy"}


@bot.message_handler(commands=['telegram'])
def open_telegram(message):
    markup = types.InlineKeyboardMarkup()
    markup.add(types.InlineKeyboardButton("Написать", url="https://сайт"))
    bot.send_message(message.chat.id,
            "Ну раз уж я не могу тебе помочь, нажимай на кнопку",
            parse_mode='html', reply_markup=markup)


@bot.message_handler(commands=['insta'])
def instagram(message):
    markup = types.InlineKeyboardMarkup()
    markup.add(types.InlineKeyboardButton("Перейти в Инстаграм", url="https://сайт"))
    bot.send_message(message.chat.id, "Переходи.", parse_mode='html', reply_markup=markup)


@bot.message_handler(commands=['poisk'])
def poisk(message):
    markup = types.InlineKeyboardMarkup()
    markup.add(types.InlineKeyboardButton("Глобальный поиск", url="https://www.google.ru/"))
    bot.send_message(message.chat.id, "Тут ты точно найдешь, что искал.", parse_mode='html', reply_markup=markup)


@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
    btn1 = types.KeyboardButton('Виды')
    btn2 = types.KeyboardButton('Подвиды')
    btn3 = types.KeyboardButton('О нас')
    btn4 = types.KeyboardButton('Сюрприз')
    markup.add(btn1, btn2, btn3, btn4)
    send_mess = f"<b>Привет {message.from_user.first_name}</b>!\nСмотри что есть:"
    bot.send_message(message.chat.id, send_mess, parse_mode='html', reply_markup=markup)

@bot.message_handler(content_types=['text'])
def mess(message):
    get_message_bot = message.text.strip()

    if get_message_bot == "Начать тест заново":
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
        btn1 = types.KeyboardButton('Виды')
        btn2 = types.KeyboardButton('Подвиды')
        btn3 = types.KeyboardButton('О нас')
        btn4 = types.KeyboardButton('Сюрприз')
        btn5 = types.KeyboardButton('Начать тест заново')
        markup.add(btn1, btn2, btn3, btn4, btn5)

        final_message = "Посмотришь еще? \nКликни на вид, с которым хочешь ознакомиться:"
    elif get_message_bot == "Виды":
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
        btn1 = types.KeyboardButton('1')
        btn2 = types.KeyboardButton('2')
        btn3 = types.KeyboardButton('3')
        btn4 = types.KeyboardButton('4')
        markup.add(btn1, btn2, btn3, btn4)
        final_message = "Отлично, смотри:"
    elif get_message_bot == "1":
        final_message = "1 вид примечателен тем, что........."
    elif get_message_bot == "2":
        final_message = "2 вид примечателен тем, что........."
    elif get_message_bot == "3":
        final_message = "3 вид примечателен тем, что........."
    elif get_message_bot == "4":
        final_message = "4 вид примечателен тем, что........."
        markup ('1', '2', '3', '4')
    else:
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
        btn1 = types.KeyboardButton('Виды')
        btn2 = types.KeyboardButton('Подвиды')
        btn3 = types.KeyboardButton('О нас')
        btn4 = types.KeyboardButton('Сюрприз')
        markup.add(btn1, btn2, btn3, btn4)
        final_message = "Стоп!\nЛучше тыкни на кнопку"
    bot.send_message(message.chat.id, final_message, parse_mode='html', reply_markup=markup)


bot.polling(none_stop=True)

certifi 2020.4.5.1
chardet 3.0.4
construct 2.8.8
decorator 4.4.2
idna 2.9
ipaddress 1.0.16
pbr 5.4.5
pip 19.0.3
PySocks 1.7.1
pyTelegramBotAPI 3.7.1
requests 2.23.0
setuptools 40.8.0
six 1.14.0
snowland-apihelper 0.0.3
snowland-smx 0.3.1
socks5 0.2.1
SQLAlchemy 1.3.16
sqlalchemy-migrate 0.13.0
sqlparse 0.3.1
Tempita 0.5.2
tornado 6.0.4
transitions 0.4.1
urllib3 1.25.9
 

Форум IT Специалистов