instagrapi
instagrapi copied to clipboard
560 Server Error When find a new followers
Hello,
I have a script where I get followers data, then process it, set sleep for 60 seconds, and run it again to check for new followers. But on random try I get this error:
560 Server Error: - for url: https://i.instagram.com/api/v1/friendships/50347285177/followers/?max_id=&count=10000&rank_token=51281359084_e1f4eb47-38a7-40b3-afb4-3dc256accaab&search_surface=follow_list_page&query=&enable_groups=true
Parsing an account with less than 4k followers. New loop without re-login.
My code:
while True:
time.sleep(60)
followers_dict_new, followers_count_new = self.get_followers()
if self.followers_count != followers_count_new and followers_count_new > self.followers_count:
new_followers = []
for f_id in followers_dict_new:
if f_id not in self.followers_dict:
new_followers.append(self.cl.username_from_user_id(f_id))
self.followers_dict = followers_dict_new
self.followers_count = followers_count_new
new_followers_string = ', '.join([str(f) for f in new_followers])
self.log(f'Подписался(лись): {new_followers_string}. Итого {followers_count_new} подписчиков.')
@iaswmn what is it doing self.get_followers()
? Show it code
@iaswmn what is it doing
self.get_followers()
? Show it code
@adw0rd hi!
def get_followers(self):
followers = self.cl.user_followers(self.user_id, use_cache=False).keys()
return followers, len(followers)
When I manually tried to send the request using private_request
with a lower count
value than the default 10000 to anything lower than 5000 it works fine, anything above it often throws 560 or 500 server errors. I think the solution would be just to lower the count
value to something lower than 5000, not tested thoroughly though.
I've experienced similar issues when calling Client.user_following
. When the Instagram account was following around 7,000 or more others, I would get repeated 500 and 560 errors. At first, based on this SO question I thought this was a kind of non-standard rate-limiting, even though I've seen normal 429
responses from Instagram when working with another library. Luckily I found this issue.
I solved my problem by editing the hard-coded count
in the definition of instagrapi.mixins.UserMixin.user_following_v1
in my site-packages and setting the hard-coded number to 5000
.
I'd be willing to open a PR to add an optional parameter, page_size
or similar, used in the query in place of the hard-coded 10000
value. I'd add this to UserMixin.user_following
, UserMixin.user_following_v1
and possibly other relevant methods. That way users could have direct control over the trade-off of how heavy the requests are versus how many requests are sent per method call.
@simoncrowe I came to the conclusion that reducing count
may not always work, Instagram throttles your requests because it thinks you're a bot and throttles your big requests, reducing count may temporarily work but Instagram will probably prompt with challenges soon when they confirm that you're a bot and also these 500 and 560 errors only appear randomly. In my case sometimes repeatedly retrying the same request works, other times you have to change both your proxy and account.