G
G
Guerro692020-06-15 17:32:44
Python
Guerro69, 2020-06-15 17:32:44

I can't understand why this is happening?

I am writing a bot in VK, I made several functions for convenience, all the vk_api libraries are imported, and therefore I had to catch the vk_api error, in one function it is caught, but in another it does not want to and gives an error:
NameError name 'vk_api' is not defined:
And it gives this on the line where it was written:
except vk_api.exceptions.ApiError:
pass

Here is the code itself:

def kick_all(user_id):
    try:
        result = cursor.execute(f'SELECT * FROM `chats`')
        row = cursor.fetchall()
        for chat_s in row:
            vk.messages.removeChatUser(chat_id=chat_s['chat_id'], member_id=user_id)
        return f"Пользователь был кикнут во всех беседах."

    except vk_api.exceptions.ApiError:
        pass

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Developer, 2020-06-15
@samodum

Because there is no vk_api declaration anywhere.
The error is exactly what it says.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question