'how to pull certain data from a list response from instagrapi

so I'm working on some code to pull the pictures of people who have liked a post on instagram. i'm using instagrapi for the api system, but when using api.media_likers which returns a list of needed info. for some reason it returns it with TypeError: 'UserShort' object is not subscriptable. Im not sure what to do because the code here:



from instagrapi import Client


insta_user = ""
insta_pass = ""

api = Client() #logs in
api.login(insta_user, insta_pass) #logs in

url = input("Please enter the url to the populer photo: ")
populer_photo_id = api.media_pk_from_url(url)   # gets media id from url given from user
print(f"got media id ==> {populer_photo_id}")

get_likes = api.media_info(populer_photo_id).dict() # gets number of likes
likes = get_likes['like_count']                     # gets number of likes


likers_res = api.media_likers(populer_photo_id) # gets the people who have liked said post (returns in list)


print(list((object['username'] for object in likers_res)))

This is supposed to return the username from the list but instead returns

Please enter the url to the populer photo: https://www.instagram.com/p/xxxxxxxxxx/
got media id ==> xxxxxxxxxxxxxxxx
Traceback (most recent call last):
  File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <module>
    print(list((object['username'] for object in likers_res)))
  File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <genexpr>
    print(list((object['username'] for object in likers_res)))
TypeError: 'UserShort' object is not subscriptable


Solution 1:[1]

you just need to change

print(list((object['username'] for object in likers_res)))

into

print(list((object.username for object in likers_res)))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 burduja