0

Trying to use requests module in eventlet python2 hit below error.

>>> import eventlet
>>> eventlet.patcher.import_patched('requests')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/eventlet/patcher.py", line 120, in import_patched
    *additional_modules + tuple(kw_additional_modules.items()))
  File "/usr/lib/python2.7/site-packages/eventlet/patcher.py", line 94, in inject
    module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
  File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 112, in <module>
    from . import utils
ImportError: cannot import name utils

So how why this module can not be patched?

How could we know if one module can be patched?

Kramer Li
  • 2,284
  • 5
  • 27
  • 55

1 Answers1

0

It's a known issue, we don't have a solution yet. Sorry.

Workaround: eventlet.patcher.import_patched('requests.__init__')

Subscribe for news on this problem here: https://github.com/eventlet/eventlet/issues/7

temoto
  • 5,394
  • 3
  • 34
  • 50
  • Also someone told me that even we use requests in eventlet, it is still not async io due to the way requests was implemented. Is it true? Or should I post another question for this? – Kramer Li Jul 01 '18 at 06:26
  • We've had a problem with patching https by urllib. AFAIK, `requests` use urllib*3* so is immune to that problem. Generally you should ask for demonstration of issue, approach is called "proof or didn't happen". – temoto Jul 01 '18 at 16:00