question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing grequests after requests breaks requests

See original GitHub issue
>>> import requests
>>> import grequests
>>> requests.get('https://google.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/requests/api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 844, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 314, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl_.py", line 264, in create_urllib3_context
    context.options |= options
  File "/usr/lib/python3.6/ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  File "/usr/lib/python3.6/ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  File "/usr/lib/python3.6/ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  [Previous line repeated 323 more times]
RecursionError: maximum recursion depth exceeded

If the order of imports is reversed, the problem no longer occurs.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:16
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
matan-carboncommented, Mar 13, 2017

Seeing this too (grequests 0.3.0, python 3.6.0), in my situation it is caused by https://github.com/kennethreitz/grequests/blob/master/grequests.py#L21 A fix would be adding ssl=False to patch_all’s arguments.

Got rid of it with

from gevent import monkey
def stub(*args, **kwargs):  # pylint: disable=unused-argument
    pass
monkey.patch_all = stub
import grequests

Anyone has a better workaround?

6reactions
syb0rgcommented, Aug 13, 2017

This was solved for me by importing requests after grequests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing grequests after requests breaks requests · Issue #103
A fix would be adding ssl=False to patch_all 's arguments. Got rid of it with. from gevent import monkey def stub(*args, **kwargs): # ......
Read more >
Developers - Importing grequests after requests breaks requests -
import requests >>> import grequests >>> requests.get('https://google.com') Traceback (most recent call last): File "<stdin>", line 1, in <module> File ...
Read more >
Python: async requests with grequests not significantly faster ...
I am just getting started in learning how to using the requests module ... coding: utf-8 # In[1]: import grequests import requests #...
Read more >
Python Examples of grequests.get - ProgramCreek.com
Python grequests.get() Examples. The following are 30 code examples of grequests.get(). ... _get_session() try: # build the requests urls = self.
Read more >
Requests Documentation - Read the Docs
Begin by importing the Requests module: ... You can tell Requests to stop waiting for a response after a given number of seconds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found