Answer the question
In order to leave comments, you need to log in
How to catch vk_api error?
There is a VK bot in the group, sends messages to users, if a person blocks sending messages, the bot tries to write to him, and throws an error Hello): [901] Can't send messages for users without permission
How can I catch this error, and if it comes out, so that the bot performs some actions.
def write_msg(self, user_id, message):
try:
self.vk.method('messages.send', {'user_id': user_id, 'message': message, 'keyboard': keyboard, 'random_id': random.randint(0, 100000000)})
except Exception as ex:
print("error (write_msg, {0}, {1}):".format(user_id, message), ex)
Answer the question
In order to leave comments, you need to log in
I personally share control prints, and then google the problem based on them
import traceback
try:
действия ()
except:
print("error", traceback.fornat_exc() )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question