示例#1
0
 def send(self, request, **kwargs) -> Response:
     # Catch urllib3 warnings for HTTPS related errors.
     insecure = False
     with warnings.catch_warnings(record=True) as w:
         warnings.filterwarnings('always')
         try:
             r = super().send(request, **kwargs)
         except Exception as e:
             try:
                 reraise_modify(e, e.request.url,
                                prepend=False)  # type: ignore
             except Exception:
                 logger.error(e)
                 raise e
         if self.protocol == 'http:':
             return r
         insecure_warnings = [
             'SNIMissingWarning', 'InsecurePlatformWarning'
         ]
         if w:
             for warning in w:
                 if any(x in str(warning) for x in insecure_warnings):
                     insecure = True
                     break
     if insecure:
         from requests.exceptions import RequestException
         msg = (
             'You are attempting to make an HTTPS request on an insecure platform,'
             ' please see:\n\n\thttps://archive.org/services/docs/api'
             '/internetarchive/troubleshooting.html#https-issues\n')
         raise RequestException(msg)
     return r
示例#2
0
 def send(self, request, **kwargs):
     # Catch urllib3 warnings for HTTPS related errors.
     insecure = False
     with warnings.catch_warnings(record=True) as w:
         warnings.filterwarnings('always')
         try:
             r = super(ArchiveSession, self).send(request, **kwargs)
         except Exception as e:
             try:
                 reraise_modify(e, e.request.url, prepend=False)
             except:
                 logger.error(e)
                 raise e
         if self.protocol == 'http:':
             return r
         insecure_warnings = ['SNIMissingWarning', 'InsecurePlatformWarning']
         if w:
             for e in w:
                 if any(x in str(e) for x in insecure_warnings):
                     insecure = True
                     break
     if insecure:
         from requests.exceptions import RequestException
         msg = ('You are attempting to make an HTTPS request on an insecure platform,'
                ' please see:\n\n\thttps://internetarchive.readthedocs.org'
                '/en/latest/troubleshooting.html#https-issues\n')
         raise RequestException(msg)
     return r