instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

[BUG] medias.py example doesn't work

Open LasterAlex opened this issue 2 months ago • 1 comments

Describe the bug Running python medias.py code that I copied with credentials filled in resulted in an error

To Reproduce Fill in credentials and run python medias.py

Traceback Log level INFO:

2025-10-03 17:07:57,454 INFO public_request: [None] [404] GET https://www.instagram.com/explore/tags/instacool/?__a=1&__d=dis
2025-10-03 17:07:58,460 INFO instagrapi: https://i.instagram.com/api/v1/tags/instacool/sections/
2025-10-03 17:08:01,927 INFO private_request: laster_alex123 [200] POST https://i.instagram.com/api/v1/tags/instacool/sections/ (269.0.0.18.75, OnePlus 6T Dev)
Traceback (most recent call last):
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/main.py", line 111, in <module>
    m = get_medias(HASHTAGS, amount=4)
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/main.py", line 86, in get_medias
    cl.hashtag_medias_top(name=hashtag, amount=amount if amount <= 9 else 9)
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/venv/lib/python3.10/site-packages/instagrapi/mixins/hashtag.py", line 393, in hashtag_medias_top
    medias = self.hashtag_medias_top_v1(name, amount)
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/venv/lib/python3.10/site-packages/instagrapi/mixins/hashtag.py", line 372, in hashtag_medias_top_v1
    return self.hashtag_medias_v1(name, amount, tab_key="top")
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/venv/lib/python3.10/site-packages/instagrapi/mixins/hashtag.py", line 328, in hashtag_medias_v1
    items, max_id = self.hashtag_medias_v1_chunk(name, amount, tab_key, max_id)
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/venv/lib/python3.10/site-packages/instagrapi/mixins/hashtag.py", line 295, in hashtag_medias_v1_chunk
    media = extract_media_v1(node["media"])
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/venv/lib/python3.10/site-packages/instagrapi/extractors.py", line 77, in extract_media_v1
    return Media(
  File "/home/laster/Programming/PycharmProjects/PlatformCommentsBot/venv/lib/python3.10/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Media
image_versions2.candidates.0.scans_profile
  Field required [type=missing, input_value={'height': 1080, 'url': '...s_spatial_image': False}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing
image_versions2.candidates.1.scans_profile
  Field required [type=missing, input_value={'height': 360, 'url': 'h...s_spatial_image': False}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing

The DEBUG log level is unreadable because it outputs a lot of useless junk that clogs up the terminal

Expected behavior I expected it to output the len of medias, not error out

Desktop

  • OS: Pop!_OS 22.04 LTS
  • Python version 3.10.12
  • instagrapi version 2.2.1

Additional context I assume this is not consistent, so try to change up the HASHTAGS variable. For example tag "trump" for whatever reason doesn't error out at the moment

LasterAlex avatar Oct 03 '25 14:10 LasterAlex

Same issue here

anvaari avatar Oct 25 '25 14:10 anvaari