A
A
Arthaus252020-12-20 16:25:13
Python
Arthaus25, 2020-12-20 16:25:13

How to write exception handling for VK API Error 18 "User was deleted or banned" error?

Here is the code (using the vk_requests library) trying to get the IDs of users' friends from the list of ids:

all_ids = list()
for id_ in tqdm(ids):
    counts = api.friends.get(user_id=id_, count=0)['count']  # look at mount of friends
    cycle = min(10, ceil(counts/1000))  # create var with counter which define number of cycles  
    
    for i in range(cycle):
        shift = 0 # var for offset
        friends = api.friends.get(user_id=id_, offset=shift, count=1000)['items']  # get the 1000 friends 
        for friend in friends:
            all_ids.append(friend)


Gives an error message
VkAPIError: error_code=18,message='User was deleted or banned',request_params={'method': 'friends.get', 'oauth': '1', 'v': '5.92', 'user_id': ' 11475787', 'count': '0'}


How to write an exception for this error? If it's not difficult for you, explain like an idiot, thanks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
ZIK1337, 2020-12-20
@Arthaus25

try except

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question