R
R
REDkiy2019-02-27 11:07:00
Python
REDkiy, 2019-02-27 11:07:00

What is the correct way to debug try ... except in Python?

There is some code like this:

try:
        validate(request_json, request_json_schema)
except ValidationError:
        print('Schema not valid!')
        return False

Line
validate(request_json, request_json_schema)
throws an exception everything is fine. We process and work.
But a certain amount of information is also output to the console, where and how specifically the incoming json does not match the required json schema.
In the case of using try ... except verbose output is lost. I don't see it in the debugger either.
What is the course of action in this situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
longclaps, 2019-02-27
@REDkiy

try:
    validate(request_json, request_json_schema)
except ValidationError as e:
    print('Schema not valid, и вот почему:')
    print(e)

Y
Yura Khlyan, 2019-02-27
@MAGistr_MTM

You can also use `logger`:

import logging

try:
    validate(request_json, request_json_schema)
except ValidationError as e:
    print('Schema not valid, и вот почему:')
    logging.exception(e)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question