GRequests monkey patch warning

Question:

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 ?

Asked By: Ram K

||

Answers:

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)
Answered By: Chris

see grequests documentation:
https://github.com/spyoungtech/grequests

GOOD:

import grequests 

import requests

BAD:

import requests 

import grequests
Answered By: Ordit Gross
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.