Can't create an exception "ApiError"

18 Views Asked by At

I'm trying to create an automatic messenger using Python and VK API (VK is a russian social network).

dataset = pd.read_csv("userID.csv")
allusers = dataset["109"][1:15] 
session = vk_api.VkApi(token="")
vk = session.get_api()
def send_msg(user_id):
  message = "Hello!"
  msg = session.method("messages.send", {"user_id": user_id,
                                         "random_id": 0,
                                         "message": message})
for item in allusers:
    try:
        send_msg(item)
    except ApiError:
        pass

Problem is: on VK, some users choose to close their Direct Messages completely, so I've got an error: [902] Can't send messages to this user due to their privacy settings When I want to iterate over a list of users ("allusers"), it stops at the ones with DM lock and doesn't go any further. I can't bypass this error with Try/Except, since it's not part of BaseException, and even if I do add it with class, it doesn't do anything:

class ApiError(Exception):
   pass

Are there any alternative solutions? Help would be much appreciated!

0

There are 0 best solutions below