
We are moving further in the development of our robot to search for state contracts. The theme of today's lesson is errors.
If our request indicates the parameters for which nothing is located, or the State Personal Service will stop responding to requests, we will get a mistake - and then our script will break. To avoid this, we will use the Try-Except syntax. Let's try to reproduce an error first.
We change a year in a request for a 2022 not yet coming ...
... and the code breaksWe will figure out how not to get such mistakes. With the help of a new condition, as it were, we say our function: try to make a request ( try ), and if it does not work ( Except ), do something else. What exactly? For example, we can withdraw some message: “Something went wrong!”
Now, if our condition is fulfilled without errors, we will get the desired result ...
... and if not, we get a mistake about the errorWith this syntax, you can prescribe specifically what error we want to avoid. Now in our code, regardless of the error, we get the message “Something went wrong!”. That mistake when we ourselves introduced the inappropriate parameter value is called Jsondecodeerror .

If we add its name to the condition, and some other will fly out-our function will break again. This time we will leave a clarification in order to be able to track other mistakes in the future and decide what to do with them.