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] is_paid_partnership field not being used when creating Story through photo_upload_to_story #1851

Open OmarGuajardo opened 7 months ago

OmarGuajardo commented 7 months ago

Getting exception when trying to do client.photo_upload_to_story()

Describe the bug I'm using the Client to perform photo_upload_to_story in the following way storyPosted = self.instagramClient.photo_upload_to_story(nextPhotoToPublishImagePath,extra_data = {'is_paid_partnership' : 0})

Where really I'm just passing an image path, weirdly enough the photo still uploads but then I get an exception saying

1 validation error for Story is_paid_partnership Field required [type=missing, input_value={'links': [], 'mentions':...], 'clips_metadata': {}}, input_type=dict]

Here's the bigger picture on how I'm using the function

if(self.nextPhotoToPublishIndex < len(self.photosToPublish)):
            # Here's how you actually post it with the instagramClient
            try:
                nextPhotoToPublishImagePath = self.photosToPublish[self.nextPhotoToPublishIndex]
                storyPosted = self.instagramClient.photo_upload_to_story(nextPhotoToPublishImagePath,extra_data = {'is_paid_partnership' : 0})
                print("posting ", self.photosToPublish[self.nextPhotoToPublishIndex])
                self.nextPhotoToPublishIndex += 1
                return self.POST_JOB_SUCCESS
            except Exception as e:
                print("post job failed because of ", e)
                return self.POST_JOB_FAIL
        else:
            return self.POST_JOB_FINISHED

Personal Comments

In instagrapi/mixins/photo.py function photo_upload_to_story, when creating Story if I add the field is_paid_partnership=False then the issue resolves but this is weird behavior since in the class definition of Story we have is_paid_partnership: Optional[bool] so I'm not sure why we are getting this error.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

andimattes commented 7 months ago

Happens on latest version (2.1.1) too. Adding is_paid_partnership=False solves the issue.

As this property is not set in the Story class and therefore will be undefined, I assume that pydantic is throwing this error as it expects a valid bollean type.

Adhambec commented 7 months ago

I have the same problem

ohs040206 commented 7 months ago

@andimattes Hi! I have the same error in my code. How can you solve this issue? I tried "cl.photo_upload_to_story(media_path, is_paid_partnership=False)" but it also made another error. How can I solve this error "TypeError: UploadPhotoMixin.photo_upload_to_story() got an unexpected keyword argument 'is_paid_partnership'"?

Adhambec commented 7 months ago

To provide a simple solution for now:

Go to the Telethon library folder and find types.py at C:\Program Files\Python39\Lib\site-packages\instagrapi/. Add a comment marker # at row 324. Then, find extractors.py at C:\Program Files\Python39\Lib\site-packages\instagrapi/ and add a comment marker # at row 426. This will solve the problem. 😄

photo_2024-04-04_12-46-47

ohs040206 commented 7 months ago

@Adhambec Wow!! Thank you so much!!

ardinusawan commented 7 months ago

Is any other solid workaround other than this? https://github.com/subzeroid/instagrapi/issues/1851#issuecomment-2036437312

For now I just use previous tag 😢

andimattes commented 7 months ago

I ended up using the official Instagram API

HaktanOzkan commented 6 months ago

To provide a simple solution for now:

Go to the Telethon library folder and find types.py at C:\Program Files\Python39\Lib\site-packages\instagrapi/. Add a comment marker # at row 324. Then, find extractors.py at C:\Program Files\Python39\Lib\site-packages\instagrapi/ and add a comment marker # at row 426. This will solve the problem. 😄

photo_2024-04-04_12-46-47

Thank you, it worked. You can try this!

itsManeka commented 6 months ago

The Story class has this parameter defined as optional, but it does not have a default value. I requested a pull request setting False as the default value. Now we have to wait and see if it is accepted.

mario-amazing commented 2 weeks ago

Fixed in instagrapi==2.1.2, issue could be closed