instagrapi
instagrapi copied to clipboard
[BUG] JSONDecodeError in public_request when accessing followers
Try Instagrapi SaaS with a free trial https://hikerapi.com/p/5GBWznd3
Describe the bug
When i try to get the followers i am getting
2024-02-28 22:04:32,410:INFO - https://i.instagram.com/api/v1/users/64086997147/info/
2024-02-28 22:04:32,678:INFO - None [400] GET https://i.instagram.com/api/v1/users/64086997147/info/ (269.0.0.18.75, OnePlus 6T Dev)
2024-02-28 22:04:33,682:INFO - https://i.instagram.com/api/v1/challenge/
2024-02-28 22:04:34,205:INFO - None [200] GET https://i.instagram.com/api/v1/challenge/ (269.0.0.18.75, OnePlus 6T Dev)
2024-02-28 22:04:35,212:INFO - https://i.instagram.com/api/v1/challenge/
2024-02-28 22:04:36,310:INFO - None [200] POST https://i.instagram.com/api/v1/challenge/ (269.0.0.18.75, OnePlus 6T Dev)
2024-02-28 22:04:37,315:INFO - https://i.instagram.com/api/v1/users/64086997147/info/
2024-02-28 22:04:38,377:INFO - None [200] GET https://i.instagram.com/api/v1/users/64086997147/info/ (269.0.0.18.75, OnePlus 6T Dev)
2024-02-28 22:04:39,706:INFO - [] [200] GET https://www.instagram.com/graphql/query/?variables=%7B%22user_id%22%3A%2265137788661%22%2C%22include_reel%22%3Atrue%7D&query_hash=ad99dd9d3646cc3c0dda65debcd266a7
2024-02-28 22:04:42,015:INFO - [] [201] GET https://www.instagram.com/mrbeastfanpage634/?__a=1&__d=dis
2024-02-28 22:04:42,016:ERROR - Status 201: JSONDecodeError in public_request (url=https://www.instagram.com/mrbeastfanpage634/?__a=1&__d=dis) >>>
2024-02-28 22:04:45,211:INFO - [] [201] GET https://www.instagram.com/mrbeastfanpage634/?__a=1&__d=dis
2024-02-28 22:04:45,212:ERROR - Status 201: JSONDecodeError in public_request (url=https://www.instagram.com/mrbeastfanpage634/?__a=1&__d=dis) >>>
2024-02-28 22:04:48,481:INFO - [] [201] GET https://www.instagram.com/mrbeastfanpage634/?__a=1&__d=dis
2024-02-28 22:04:48,482:ERROR - Status 201: JSONDecodeError in public_request (url=https://www.instagram.com/mrbeastfanpage634/?__a=1&__d=dis) >>>
2024-02-28 22:04:49,485:INFO - https://i.instagram.com/api/v1/users/65137788661/info/
2024-02-28 22:04:50,381:INFO - None [200] GET https://i.instagram.com/api/v1/users/65137788661/
cl.load_settings(f"{file_name}")
user_info = cl.user_info_by_username(target)
print(user_info)
if user_info is None:
raise HTTPException(status_code=404, detail="User not found")
user_id = user_info.pk
followers = cl.user_followers(user_id=user_id, amount=amount)
scraped_usernames = [cl.user_info(
follower_id).username for follower_id in followers if cl.user_info(follower_id)]
print(scraped_usernames)
Desktop (please complete the following information):**
- OS: Mac Osx
- instagrapi version Latest
it is not a bug, just changing in the api, instead of accessing the keys in the return dict using dict.<key>, you should use the method .get also you should use the method user_info_by_username_v1 not user_info_by_username and add .model_dump() so your code should look like this
cl.load_settings(f"{file_name}")
user_info = cl.user_info_by_username_v1(target).model_dump()
print(user_info)
if user_info is None:
raise HTTPException(status_code=404, detail="User not found")
user_id = user_info.get("pk")
followers = cl.user_followers(user_id=user_id, amount=amount)
scraped_usernames = [cl.user_info(
follower_id).username for follower_id in followers if cl.user_info(follower_id)]
print(scraped_usernames)