How to make Universal Parser only for parsing?

I am trying to get content from external feeds on my Django website with Universal Parser . I want to have some user error handling, for example. if the user supplies a URL that is not a feed. When I tried how feedparser responds to erroneous input, I was surprised to see that feedparser did not throw Exceptions at all. For instance. on HTML content, it tries to parse some information from HTML code and into non-existent domains, it returns a mostly empty dictionary:

{'bozo': 1,
'bozo_exception': URLError(gaierror(-2, 'Name or service not known'),),
'encoding': 'utf-8',
'entries': [],
'feed': {},
'version': None}

Another erroneous input appears in the values status_codeor namespacesin the returned dictionary.

So, what is the best approach for correct error checking without resorting to an infinite cascade if .. elif .. elif ...?

+3
source share

Source: https://habr.com/ru/post/1782092/