@yk_vova

Код работал, а при загрузке на Heroku перестал работать .В чем проблема?

На локальной машине код работал , а при загрузке перестал .В чем может быть проблема ? и как ее решить
spoiler

import telebot

from telebot import types
import requests
from bs4 import BeautifulSoup
import os

bot = telebot.TeleBot(token)

@bot.message_handler(commands= ['start'])
def first(message):
    key = types.ReplyKeyboardMarkup(True, False)
    key.row('Расписание', 'ГДЗ')
    send = bot.send_message(message.from_user.id, "Меню", reply_markup=key)
    bot.register_next_step_handler(send, menu)

def menu(message):
    if message.text == 'Расписание':
        img = open('2020.09.04-18.08.png', 'rb')
        bot.send_photo(message.chat.id, photo=img)
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
        keyboard.add(*[types.KeyboardButton(name) for name in ['Домой']])
        send = bot.send_message(message.from_user.id, "2 lvl", reply_markup=keyboard)
        bot.register_next_step_handler(send, subject)

    elif message.text == 'ГДЗ':
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
        keyboard.add(*[types.KeyboardButton(name) for name in ['Физика', 'Алгебра', 'Русский язык']])
        keyboard.add(*[types.KeyboardButton(name) for name in ['Геометрия', 'да', '']])
        keyboard.add(*[types.KeyboardButton(name) for name in ['нет', 'да', '']])
        keyboard.add(*[types.KeyboardButton(name) for name in ['нет', 'да', '']])
        keyboard.add(*[types.KeyboardButton(name) for name in ['Домой']])
        send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
        bot.register_next_step_handler(send, subject)

def subject(message):
    if message.text == 'Русский язык':
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
        keyboard.row('Назад')
        send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
        bot.register_next_step_handler(send, back)

    elif message.text == 'Алгебра':
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
        keyboard.row('Назад')
        send = bot.send_message(message.from_user.id, "Введите номер упражнения", reply_markup=keyboard)
        bot.register_next_step_handler(send, alg)

    elif message.text == 'Физика':
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
        keyboard.row('Назад')
        send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
        bot.register_next_step_handler(send, back)

    elif message.text == 'Русский язык':
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
        keyboard.row('Назад')
        send = bot.send_message(message.from_user.id, "text", reply_markup=keyboard)
        bot.register_next_step_handler(send, back)

    elif message.text == 'Геометрия':
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
        keyboard.row('Назад')
        send = bot.send_message(message.from_user.id, "Введите номер упражнения", reply_markup=keyboard)
        bot.register_next_step_handler(send, geom, back)

    elif message.text == 'Домой':
        first(message)
def alg(message):
    if message.text != 'Назад':
        intmes = int(message.text)
        listnum = range(1, 939)
        if intmes in listnum:
            per = str(intmes)
            URL = 'https://gdz.ru/class-8/algebra/merzlyak/' + per + '-nom'
            HEADERS = {
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
                'accept': '*/*'}

            def get_html(url, params=None):
                r = requests.get(url, headers=HEADERS, params=params)
                return r

            imgg = ''
            imgg3 = 0
            imgg4 = 0
            def get_content(html):
                global imgg

                soup = BeautifulSoup(html, 'html.parser')
                divs = soup.find_all('div', {'class': 'with-overtask'})
                sc = 1
                imgg3 = 0
                imgg4 = 0
                for div in divs:
                    imgg = div.find('img')['src']
                    if sc == 1:
                        imgg2 = 'https:' + imgg
                    elif sc == 2:
                        imgg3 = 'https:' + imgg
                    elif sc == 3:
                        imgg4 = 'https:' + imgg
                    sc += 1
                # if div != None:

                if imgg2 != 0:
                    p = requests.get(imgg2)  # download
                    out = open(r"C:\Users\vayak\PycharmProjects\pythonProject5\img.jpg", "wb")
                    out.write(p.content)
                    out.close()
                    img = open('img.jpg', 'rb')
                    bot.send_photo(message.chat.id, photo=img)
                    img.close()
                    file_path = r'C:\Users\vayak\PycharmProjects\pythonProject5\img.jpg'
                    os.remove(file_path)# delete
                if imgg3 != 0:
                    p = requests.get(imgg3)  # download
                    out = open(r"C:\Users\vayak\PycharmProjects\pythonProject5\img.jpg", "wb")
                    out.write(p.content)
                    out.close()
                    img = open('img.jpg', 'rb')
                    bot.send_photo(message.chat.id, photo=img)
                    img.close()
                    file_path = r'C:\Users\vayak\PycharmProjects\pythonProject5\img.jpg'
                    os.remove(file_path)  # delete
                if imgg4 != 0:
                    p = requests.get(imgg4)  # download
                    out = open(r"C:\Users\vayak\PycharmProjects\pythonProject5\img.jpg", "wb")
                    out.write(p.content)
                    out.close()
                    img = open('img.jpg', 'rb')
                    bot.send_photo(message.chat.id, photo=img)
                    img.close()
                    file_path = r'C:\Users\vayak\PycharmProjects\pythonProject5\img.jpg'
                    os.remove(file_path)  # delete

                send = bot.send_message(message.from_user.id, "Решение упражнения " + per)
                bot.register_next_step_handler(send, back)  # recurse



            def parse():
                html = get_html(URL)
                if html.status_code == 200:
                    get_content(html.text)
                return html

            parse()

  • Вопрос задан
  • 49 просмотров
Пригласить эксперта
Ответы на вопрос 1
alfss
@alfss
Исправить пути до изображения
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы