GRequests monkey patch warning

Tags: , ,



I get the following warning each time , though the module works as expected :

/usr/local/lib/python3.7/site-packages/grequests.py:21: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (/usr/local/lib/python3.7/site-packages/urllib3/util/__init__.py)', 'urllib3.contrib.pyopenssl (/usr/local/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py)']. 
  curious_george.patch_all(thread=False, select=False)

I tried the workaround mentioned at this github issue but that doesn’t work.

How to get rid of this warning ?

Answer

For grequests you would need to add the following code before other modules try to import / load gevent and ssl:

from gevent import monkey as curious_george
curious_george.patch_all(thread=False, select=False)


Source: stackoverflow