subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.38k stars 685 forks source link

[BUG] media_info() error #1443

Closed ahmedfamhy3 closed 1 year ago

ahmedfamhy3 commented 1 year ago

Describe the bug A error happens when trying to get media_info() even if logged in, the media i'm trying to get is public

To Reproduce

cl = InstaCli()
d = cl.media_pk_from_url('https://www.instagram.com/p/CKxCFE3BJW3/')
print(d) #it prints the media id without any problem
url=cl.media_info(d) # here comes the error

Traceback

1 validation error for UserShort
profile_pic_url_hd
  Field required [type=missing, input_value={'id': '8530598273', 'is_...lse, 'pk': '8530598273'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.0.1/v/missing
Traceback (most recent call last):
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 259, in media_info
    media = self.media_info_gql(media_pk)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 213, in media_info_gql
    return extract_media_gql(data["shortcode_media"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\extractors.py", line 105, in extract_media_gql
    user = extract_user_short(media["owner"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\extractors.py", line 193, in extract_user_short
    return UserShort(**data)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 150, in init
    pydantic_self.pydantic_validator.validate_python(data, self_instance=pydantic_self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for UserShort
profile_pic_url_hd
  Field required [type=missing, input_value={'id': '8530598273', 'is_...lse, 'pk': '8530598273'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.0.1/v/missing
Traceback (most recent call last):
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 259, in media_info
    media = self.media_info_gql(media_pk)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 213, in media_info_gql
    return extract_media_gql(data["shortcode_media"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\extractors.py", line 105, in extract_media_gql
    user = extract_user_short(media["owner"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\extractors.py", line 193, in extract_user_short
    return UserShort(**data)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 150, in init
    pydantic_self.pydantic_validator.validate_python(data, self_instance=pydantic_self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for UserShort
profile_pic_url_hd
  Field required [type=missing, input_value={'id': '8530598273', 'is_...lse, 'pk': '8530598273'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.0.1/v/missing

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\private.py", line 360, in _send_private_request
    response.raise_for_status()
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://i.instagram.com/api/v1/media/2499788413075756471/info/

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:\Users\Ahmed\Desktop\New\downloaders\instagram.py", line 14, in <module>
    url=cl.media_info(d)
        ^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 269, in media_info
    media = self.media_info_v1(media_pk)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 236, in media_info_v1
    raise e
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 230, in media_info_v1
    result = self.private_request(f"media/{media_pk}/info/")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\private.py", line 535, in private_request
    raise e
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\private.py", line 520, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\private.py", line 459, in _send_private_request
    raise ClientError(e, response=e.response, **last_json)
instagrapi.exceptions.ClientError: Please wait a few minutes before you try again.

Expected behavior It should have returned the media info

adw0rd commented 1 year ago
image

Cannot reproduce

instagrapi.exceptions.ClientError: Please wait a few minutes before you try again.

Instagram does not like that your account or IP address is very active, asks you to wait, I usually sleep from 30 minutes, if it repeats, then I sleep more

To solve this problem, I bought 5000 proxies and thousands of accounts, or use https://lamadava.com/ or https://datalama.io/ to get data, it will be much cheaper

ahmedfamhy3 commented 1 year ago

I used cloudflare WARP+

Traceback (most recent call last):
  File "c:\Users\Ahmed\Desktop\New\downloaders\instagram.py", line 15, in <module>
    url=cl.media_info(d)
        ^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 269, in media_info
    media = self.media_info_v1(media_pk)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\mixins\media.py", line 237, in media_info_v1
    return extract_media_v1(result["items"].pop())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\extractors.py", line 60, in extract_media_v1
    media["user"] = extract_user_short(media.get("user"))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagrapi\extractors.py", line 193, in extract_user_short
    return UserShort(**data)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 150, in init
    pydantic_self.pydantic_validator.validate_python(data, self_instance=pydantic_self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for UserShort
pk
  Input should be a valid string [type=string_type, input_value=8530598273, input_type=int]
    For further information visit https://errors.pydantic.dev/2.0.1/v/string_type
profile_pic_url_hd
  Field required [type=missing, input_value={'has_anonymous_profile_p...y_downloads_enabled': 0}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.0.1/v/missing
adw0rd commented 1 year ago

pip install -U instagrapi

and try again

ahmedfamhy3 commented 1 year ago

It works, thanks