subzeroid / instagrapi

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

[BUG] HTTPError: 500 Server Error / ClientError: Unknown Server Error #678

Closed 69haha420 closed 1 year ago

69haha420 commented 2 years ago

Describe the bug When I try to post on Instagram I get some wierd error I didn't find in documentation. It worked the first time and now its not working anymore even when I try to post it with an example code. EDIT: typo

To Reproduce

    async def igpost(self, ctx, *message):
        if ctx.message.attachments:
            photo = igcl.photo_download_by_url(url=ctx.message.attachments[0].url, folder="C:/ZmotanBOT/data", filename="temppostpic")
            igcl.photo_upload(path=photo,
                              location=Location(name="zmotan.com", lat=46.057661, lng=14.505980),
                              usertags=[Usertag(user=igzmotaninfo, x=0.5, y=0.5)],
                              caption=message)
            return
        else:
            print("no pic")

Traceback

Ignoring exception in command igpost:
Traceback (most recent call last):
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\instagrapi\mixins\private.py", line 298, in _send_private_request
    response.raise_for_status()
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://i.instagram.com/api/v1/media/configure/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\ZmotanBOT\cogs\IG.py", line 49, in igpost
    igcl.photo_upload(path=photo,
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\instagrapi\mixins\photo.py", line 234, in photo_upload
    if self.photo_configure(
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\instagrapi\mixins\photo.py", line 310, in photo_configure
    return self.private_request("media/configure/", self.with_default_data(data))
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\instagrapi\mixins\private.py", line 445, in private_request
    raise e
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\instagrapi\mixins\private.py", line 432, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\instagrapi\mixins\private.py", line 374, in _send_private_request
    raise ClientError(e, response=e.response, **last_json)
instagrapi.exceptions.ClientError: Unknown Server Error.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\WORK\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientError: Unknown Server Error.

Expected behavior Should upload the photo from attachment as a post.

Screenshots Screenshot_87

Desktop (please complete the following information):

Thanks in advance!

Best regards, zmotan

adw0rd commented 2 years ago

@zmotan cannot reproduce

image

from instagrapi import Client
from instagrapi.types import Location, Usertag

cl = Client(...)
cl.login(...)
media = cl.media_info(cl.media_pk_from_url("https://www.instagram.com/p/B8RaCaPAEtT/"))
photo = cl.photo_download_by_url(media.thumbnail_url)
user = cl.user_info(cl.user_id)
cl.photo_upload(path=photo, location=Location(name="zmotan.com", lat=46.057661, lng=14.505980), usertags=[Usertag(user=user, x=0.5, y=0.5)], caption="TEST MSG")

Media(pk='2847468023696840083', id='2847468023696840083_29817608135', code='CeEPRS9u9WT', taken_at=datetime.datetime(2022, 5, 27, 15, 17, 41, tzinfo=datetime.timezone.utc), media_type=1, product_type='feed', thumbnail_url=HttpUrl('https://scontent-msp1-1.cdninstagram.com/v/t51.2885-15/284591628_308939281445365_8821881272139351405_n.jpg?se=7&stp=dst-jpg_e35&_nc_ht=scontent-msp1-1.cdninstagram.com&_nc_cat=101&_nc_ohc=Yw_k35yOP_UAX_-rIka&edm=ACqnv0EBAAAA&ccb=7-5&ig_cache_key=Mjg0NzQ2ODAyMzY5Njg0MDA4Mw%3D%3D.2-ccb7-5&oh=00_AT93ekGbfPrk-LFXtjCfdsl3uJrJbSAgaYZZgOSh_9tubg&oe=6297E455&_nc_sid=9ec724', scheme='https', host='scontent-msp1-1.cdninstagram.com', tld='com', host_type='domain', port='443', path='/v/t51.2885-15/284591628_308939281445365_8821881272139351405_n.jpg', query='se=7&stp=dst-jpg_e35&_nc_ht=scontent-msp1-1.cdninstagram.com&_nc_cat=101&_nc_ohc=Yw_k35yOP_UAX_-rIka&edm=ACqnv0EBAAAA&ccb=7-5&ig_cache_key=Mjg0NzQ2ODAyMzY5Njg0MDA4Mw%3D%3D.2-ccb7-5&oh=00_AT93ekGbfPrk-LFXtjCfdsl3uJrJbSAgaYZZgOSh_9tubg&oe=6297E455&_nc_sid=9ec724'), location=Location(pk=213606897, name='Ljubljana, Slovenia', phone='', website='', category='', hours={}, address=None, city=None, zip=None, lng=14.506, lat=46.0576, external_id=111980668819694, external_id_source='facebook_places'), user=UserShort(pk='29817608135', username='adw0rd_', full_name='Mikhail Andreev', profile_pic_url=HttpUrl('https://scontent-msp1-1.cdninstagram.com/v/t51.2885-19/266338300_211602184377529_159610427246423029_n.jpg?stp=dst-jpg_s150x150&_nc_ht=scontent-msp1-1.cdninstagram.com&_nc_cat=101&_nc_ohc=R5TltjsL1ksAX99THWX&edm=ACqnv0EBAAAA&ccb=7-5&oh=00_AT9A85sf2ze3uEs4BkIqX0Vpob_Tc905zFnWLfvUWXexqQ&oe=62986B83&_nc_sid=9ec724', scheme='https', host='scontent-msp1-1.cdninstagram.com', tld='com', host_type='domain', port='443', path='/v/t51.2885-19/266338300_211602184377529_159610427246423029_n.jpg', query='stp=dst-jpg_s150x150&_nc_ht=scontent-msp1-1.cdninstagram.com&_nc_cat=101&_nc_ohc=R5TltjsL1ksAX99THWX&edm=ACqnv0EBAAAA&ccb=7-5&oh=00_AT9A85sf2ze3uEs4BkIqX0Vpob_Tc905zFnWLfvUWXexqQ&oe=62986B83&_nc_sid=9ec724'), profile_pic_url_hd=None, is_private=False, stories=[]), comment_count=0, like_count=0, has_liked=False, caption_text='TEST MSG', accessibility_caption=None, usertags=[Usertag(user=UserShort(pk='29817608135', username='adw0rd_', full_name='Mikhail Andreev', profile_pic_url=HttpUrl('https://scontent-msp1-1.cdninstagram.com/v/t51.2885-19/266338300_211602184377529_159610427246423029_n.jpg?stp=dst-jpg_s150x150&_nc_ht=scontent-msp1-1.cdninstagram.com&_nc_cat=101&_nc_ohc=R5TltjsL1ksAX99THWX&edm=ACqnv0EBAAAA&ccb=7-5&oh=00_AT9A85sf2ze3uEs4BkIqX0Vpob_Tc905zFnWLfvUWXexqQ&oe=62986B83&_nc_sid=9ec724', scheme='https', host='scontent-msp1-1.cdninstagram.com', tld='com', host_type='domain', port='443', path='/v/t51.2885-19/266338300_211602184377529_159610427246423029_n.jpg', query='stp=dst-jpg_s150x150&_nc_ht=scontent-msp1-1.cdninstagram.com&_nc_cat=101&_nc_ohc=R5TltjsL1ksAX99THWX&edm=ACqnv0EBAAAA&ccb=7-5&oh=00_AT9A85sf2ze3uEs4BkIqX0Vpob_Tc905zFnWLfvUWXexqQ&oe=62986B83&_nc_sid=9ec724'), profile_pic_url_hd=None, is_private=False, stories=[]), x=0.5, y=0.5)], video_url=None, view_count=0, video_duration=0.0, title='', resources=[], clips_metadata={})
69haha420 commented 2 years ago

Thank you for your time and answer, I will do few tests in next few days and will post an update.

Best regards, Z

ghrlt commented 2 years ago

From my experience, if your photo is not a JPEG or WEBP file, it will not work, thus might trigger such error.

Make sure to convert any .png to .jpg first ;)

69haha420 commented 2 years ago

From my experience, if your photo is not a JPEG or WEBP file, it will not work, thus might trigger such error.

Make sure to convert any .png to .jpg first ;)

Thank you for clearing that out, I believe this might be the root of the problem.

Cheers 🍻