D
D
Drumh2014-06-07 22:34:26
Python
Drumh, 2014-06-07 22:34:26

VK API Exception Handling

Hello. Actually the title reflects the essence of the question. Have a function

def wall_post(message, vkapi, user_id):
    try:
        vkapi.wall.post(owner_id=user_id, message=message)
        print("Сообщение '" + message + "' успешно отправлено на стену пользователя " + user_id)
    except Exception as e:
        print(str(e))
        sleep(10)
        vkapi.wall.post(owner_id=user_id, message=message)

At some point, an exception pops up about the fact that you need to enter a captcha. How do I handle this particular exception? Those. as for example
except ZeroDivisionError: ...
The exception text itself:
14. Captcha needed. params = [{'key': 'oauth', 'value': '1'}, {'key': 'method', 'value': 'wall.post'}, {'key': 'access_token', 'value': 'b7359cbb3e7f8285d1c75acafc6168a4ccf600d2fb1419a859ef05362b2c59bf339608668de58496bc940'}, { 'key': 'timestamp', 'value': '1402169419'}, { 'key': 'owner_id', 'value': '115 809 454'}, { 'key': 'v', 'value': '5.20'}, {'key': 'message', 'value': 'f'}]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Beach, 2016-01-19
@Zuzik3500

Remove spaces before colons and you will be happy. You cannot rely on examples alone, they are not always working for them.

O
onlooked, 2016-01-19
@onlooked

tab...

A
Alexander Taratin, 2014-06-07
@Drumh

You see the number 14 at the beginning. This is the error code. All api errors have different codes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question