A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-October/149799.html below:

[Python-Dev] Investigating time for `import requests`

[Python-Dev] Investigating time for `import requests` [Python-Dev] Investigating time for `import requests`Eric V. Smith eric at trueblade.com
Sun Oct 8 18:46:12 EDT 2017
> The easiest workaround at the moment is still pretty clumsy:
> 
> def import_SLLError():
>      from requests.exceptions import SLLError
>      return SLLError
> 
> ...
> 
> 
>      except import_SLLError():
> 
> 
> But what happens if that gives you an ImportError?

You can't catch a requests exception unless requests has already been 
imported, you could do something like:

     except Exception as ex:
         if 'requests' in sys.modules:
             import requests  # this is basically free at this point
             if isinstance(ex, requests.exceptions):
                 ...

Eric.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4