Y
Y
yamudaqq2020-03-15 20:02:11
css
yamudaqq, 2020-03-15 20:02:11

How to find out the vk api error number?

For example, after creating a session, I send a crooked request:

>>>api.photos.getOwnerPhotoUploadServer(owner_id = 2-1312)
vk.exceptions.VkAPIError: 7. Permission to perform this action is denied. request_params = {'method': 'photos.getOwnerPhotoUploadServer', 'oauth': '1', 'v': '5.103', 'owner_id': '-1310'}

I get the error "vk.exceptions.VkAPIError: 7."
How can I get the number seven out of it?
In my case, when using one of the methods, it can return more than one error. This is either 15 or 6. It doesn’t matter what their meaning is, but the essence, the program needs to somehow distinguish between them. And it is desirable to do this using the "vk" module. Directly, using requests, I can get their number, but what if there is a way to get them using this module? Even when using exceptions, this error cannot be put into a variable in any way, so that later, for example, it can be parsed by a space character.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lukoie, 2019-08-11
@lukoie

And what, they didn’t find in the site code which one they used?

O
o5a, 2020-03-16
@yamudaqq

try:
    api.photos.getOwnerPhotoUploadServer #нужный метод
except Exception as e:
    print(e.code) #код ошибки
    print(e.message) #текст ошибки

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question