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

2017年10月08日 15:49:14 -0700

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.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to