K
K
kolomiec_artiom2018-08-28 21:21:10
Python
kolomiec_artiom, 2018-08-28 21:21:10

How to get errors from a function in python?

Good evening friends!
I have a bot. I send a message with:

api.messages.send(access_token=token, user_id=str(id_user), message=message, attachment='')

If the bot sends too many messages, then this method will fail. Error code: 14
(Taken from here: https://vk.com/dev/errors)
I don't know how to fix this error. Tried like this:
error = api.messages.send(access_token=token, user_id=str(id_user), message=message, attachment='')

but this is how the error occurs. So how do you take it out? I tried traceback, but there is an error in its entirety, and not just its number

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Febel, 2018-08-29
@Febel

try + exception.

try:
       Пробуем что то сделать например взять данные с сайта.
        return данные
               
    except Exception:
        return "Не могу подключиться!"
        pass

This way you will get around your mistake.
But...
You shouldn't constantly use try + exception, sometimes very important errors can hide behind it that you won't see. - and that's bad

X
x67, 2018-08-28
@x67

Use a
try block:
DoSmthing()
except:
print('err occured')
There is a usage example on the internet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question