Есть код для скачивания видео/фоток из инстаграма.
Но при попытке скачивания выдает ошибку
Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=NameError("name 'checking_video' is not defined")>
Traceback (most recent call last):
File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\артем\Desktop\instagram-master\main1.py", line 34, in downloader
if checking_video==True:
NameError: name 'checking_video' is not defined
Вот сам код
import os
import requests
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
TOKEN = ''
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start', 'help'])
async def start(message: types.Message):
await bot.send_message(message.chat.id, text='привет')
@dp.message_handler(content_types=['text'])
async def downloader(message: types.Message):
instagram_post = message.text
if "instagram.com" in instagram_post:
changing_url = instagram_post.split("/")
url_code = changing_url[4]
url = f"https://instagram.com/p/{url_code}?__a=1"
try:
global checking_video
visit = requests.get(url).json()
checking_video = visit['graphql']['shortcode_media']['is_video']
except:
await bot.send_message(message.chat.id, text="Send Me Only Public Instagram Posts")
if checking_video==True:
try:
video_url = visit['graphql']['shortcode_media']['video_url']
await bot.send_video(message.chat.id, video=video_url)
except:
pass
elif checking_video==False:
try:
post_url = visit['graphql']['shortcode_media']['display_url']
await bot.send_photo(message.chat.id, photo=post_url)
except:
pass
else:
await bot.send_message(message.chat.id, text="I Cant Send You Private Posts")
else:
await bot.send_message(message.chat.id, text="Kindly Send Me Public Instagram Video/Photo Url")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
Что не так?