Answer the question
In order to leave comments, you need to log in
Heroku bot gives an error, although the bot works in the console, what should I do?
Hello everyone, I uploaded the bot to Heroku
Everything went well, there were no errors
Here is the bot code:
import logging
import asyncio
from bs4 import BeautifulSoup as BS
import requests
from aiogram import Bot, Dispatcher, executor, types
import config
import json
import re
logging.basicConfig(level=logging.INFO)
bot = Bot(token = config.token)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def send_welcome(message: types.Message):
await bot.send_message(message.from_user.id , 'Отправь мне ссылку в формате "https://www.instagram.com", "https://www.tiktok.com" или "https://vm.tiktok.com", а я тебе отправлю фотографию :)', disable_web_page_preview='true')
@dp.message_handler()
async def echo(message: types.Message):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
JS_SHARED_DATA_PATTERN = re.compile('window._sharedData = ({.+});')
URL = message.text
if URL.startswith('https://www.instagram.com') == True :
r = requests.get(URL, headers=headers, allow_redirects=True)
soup = BS(r.content, 'html.parser')
script = soup.find('script', attrs={'type': "text/javascript"}, text=JS_SHARED_DATA_PATTERN)
m = JS_SHARED_DATA_PATTERN.search(script.text)
shared_data_text = m.group(1)
data = json.loads(shared_data_text)
url = data.get('entry_data').get('PostPage')[0].get('graphql').get('shortcode_media')
await bot.send_video(message.from_user.id, url)
2020-07-19T11:42:14.766277+00:00 app[worker.1]: File "main.py", line 45, in echo
2020-07-19T11:42:14.766278+00:00 app[worker.1]: shared_data_text = m.group(1)
2020-07-19T11:42:14.766278+00:00 app[worker.1]: AttributeError: 'NoneType' object has no attribute 'group'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question