Feedparser.parse () 'SSL: CERTIFICATE_VERIFY_FAILED'

I had a problem with SSL when analyzing the feedparser of the HTTPS RSS feed, I donโ€™t know what to do, because I canโ€™t find the documentation for this error when it comes to feedparser:

 >>> import feedparser >>> feed = feedparser.parse(rss) >>> feed {'feed': {}, 'bozo': 1, 'bozo_exception': URLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),), 'entries': []} >>> feed["items"] [] >>> 
+7
source share
2 answers

Thanks, cmidi for the answer that was for the "monkey patch" using ssl._create_default_https_context = ssl._create_unverified_context

 import feedparser import ssl if hasattr(ssl, '_create_unverified_context'): ssl._create_default_https_context = ssl._create_unverified_context feed = feedparser.parse(rss) #<<WORKS!! 
+17
source

This is because Python is starting to apply default certificate verification for stdlib http clients .

An excellent explanation of the rationale for the changes can be found in this article on Redhat . There is also information on how to monitor and troubleshoot this new situation.

Both of the previous links explain how to avoid certificate verification in separate connections (which is not a solution for feedparser users):

 import ssl # This restores the same behavior as before. context = ssl._create_unverified_context() urllib.urlopen("https://no-valid-cert", context=context) 

Currently, feedparser users can avoid certificate verification only with monkeypatching , which is highly undesirable as it affects the entire application.

The code for changing the behavior of the application as a whole will be as follows (the code is taken from PEP-476):

 import ssl try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: # Legacy Python that does not verify HTTPS certificates by default pass else: # Handle target environment that does not support HTTPS verification ssl._create_default_https_context = _create_unverified_https_context 

There is a problem about this on the feedparser tracker : How to fix SSL: CERTIFICATE_VERIFY_FAILED? .

0
source

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


All Articles