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

StoryMention location attr error #305

Closed alosoft closed 3 years ago

alosoft commented 3 years ago

Describe the bug uploading story with mentions or location throws error

To Reproduce client.photo_upload_to_story( path=builder.path, caption=data['caption'], mentions=builder.mentions, locations=story_locations, links=[StoryLink(webUri='https://www.google.com')], hashtags=story_hashtags )

Traceback Traceback (most recent call last): File "C:\Users\Alonso\Desktop\Desktop\alosoft-master\alosoft-master\app_api\scheduler_views.py", line 160, in schedulePost upload: Story = client.photo_upload_to_story( File "C:\Users\Alonso\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\photo.py", line 317, in photo_upload_to_story if self.photo_configure_to_story( File "C:\Users\Alonso\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\photo.py", line 459, in photo_configure_to_story mention.location = self.location_complete(mention.location) AttributeError: 'list' object has no attribute 'location'

Expected behavior code references mention.location which is invalid

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context code references mention.location which is invalid

adw0rd commented 3 years ago

@alosoft show how you created builder and story_locations

alosoft commented 3 years ago

@adw0rd this is the method for building the story

    try:
        stories: List[StoryBuilder] = []
        for path in paths:
            builder = StoryBuilder(
                Path(path),
                caption=caption,
                mentions=mentions
            )
            stories.append(builder.video(15) if is_video else builder)
        return stories
    except Exception as error:
        print(error)
adw0rd commented 3 years ago

@alosoft can't see how story_locations was created

alosoft commented 3 years ago

@adw0rd relevant code

try:
        story_locations: List[StoryLocation] = []
        if location is not None:
            story_locations.append(
                [StoryLocation(location=location, x=0.33,
                               y=0.22, width=0.4, height=0.7)]
            )

        story_hashtags: List[StoryHashtag] = []
        # collect tags from caption
        caption_split: List[str] = data['caption'].split('#')
        for tag in caption_split:
            if  len(tag.strip()) > 0:
                try:
                    ht = client.hashtag_info(tag.strip())
                    story_hashtags.append(
                        StoryHashtag(hashtag=ht, x=0.23,
                                     y=0.32, width=0.5, height=0.22)
                    )
                except Exception as error:
                    pass

        video_builder = buildStory(
            is_video=True, paths=videos, caption=data['caption'], mentions=story_mentions)

        image_builder = buildStory(
            is_video=False, paths=images, caption=data['caption'], mentions=story_mentions)

        if image_builder is None and video_builder is None:
            raise Exception

        results: List[Story] = []

        for builder in image_builder:
            upload: Story = client.photo_upload_to_story(
                path=builder.path,
                caption=data['caption'],
                mentions=builder.mentions,
                locations=story_locations,
                links=[StoryLink(webUri='https://corps-ai.herokuapp.com')],
                hashtags=story_hashtags
            )
            results.append(upload)

        for builder in video_builder:
            upload: Story = client.video_upload_to_story(
                path=builder.path,
                caption=data['caption'],
                mentions=builder.mentions,
                locations=story_locations,
                hashtags=story_hashtags
            )
            results.append(upload)

        deleteFiles(images, videos)
        postExtras(data, client, None)

        response: List[ResponseData] = []
        for result in results:
            response.append(
                getResponseData(
                    upload=upload,
                    type='story',
                    id=data['id']
                )
            )

        try:
            return HttpResponse(json.dumps({'response': response}), status=200, content_type='application/json')
        except Exception as error:
            print(error)
            return HttpResponse(error.message, status=500)

    except Exception as error:
        deleteFiles(images, videos)
        print(error)
        return HttpResponse(error.message, status=500)

here is the buildStory method

      try:
          stories: List[StoryBuilder] = []
          for path in paths:
              builder = StoryBuilder(
                  Path(path),
                  caption=caption,
                  mentions=mentions
              )
              # stories.append(builder.video(15) if is_video else builder)
              stories.append(builder if is_video else builder)
          return stories
      except Exception as error:
          print(error)
adw0rd commented 3 years ago

@alosoft need a StoryLocation list, not a list of List[StoryLocation]:

try:
        story_locations: List[StoryLocation] = []
        if location is not None:
            story_locations.append(
                [StoryLocation(location=location, x=0.33,
                               y=0.22, width=0.4, height=0.7)]
            )

to

try:
        story_locations: List[StoryLocation] = []
        if location is not None:
            story_locations.append(
                StoryLocation(location=location, x=0.33,
                               y=0.22, width=0.4, height=0.7)
            )
adw0rd commented 3 years ago

@alosoft your result looks like this:

story_locations = [[StoryLocation(location=location, x=0.33, y=0.22, width=0.4, height=0.7)]]

and should:

story_locations = [StoryLocation(location=location, x=0.33, y=0.22, width=0.4, height=0.7)]

alosoft commented 3 years ago

@adw0rd Thanks. Good eye