Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
grequests with requests has collision

I am using grequests python module to call some APIs. I want to make two functions.

  1. A single request(use requests module)
  2. A multiple request(use grequests module)

When I use two modules in two different files, it runs normally, but when I import two modules in the same file, requests module fall in infinity recursive.

  #!/usr/bin/env python                                                                                                                                                                                          
  #-*- encoding:utf-8 -*-                                                                                                                                                                                        

  import requests                                                                                                                                                                                                
  import grequests                                                                                                                                                                                               

  def SingleRequest():                                                                                                                                                                                           
      rs = requests.get("www.example.com")                                                                                                                                                                          
      return rs                                                                                                                                                                                             

  def MultiRequest():                                                                                                                                                                                            
      urls = [                                                                                                                                                                                                   
          "www.example1.com", 
          "www.example2.com",  
          "www.example3.com"                                                                                                
      ]                                                                                                                                                                                                          
      rs = [grequests.get(u) for u in urls]                                                                                                                                                        
      rs_map = grequests.map(rs);                                                                                                                                                                                
      return rs_map;       

If I call MultiRequest() -> do Well!

but if I call SingleRequest() ..... ↓

Exception Type: RecursionError
Exception Value: maximum recursion depth exceeded
Exception Location: /usr/local/lib/python3.6/ssl.py in options, line 459

/usr/local/lib/python3.6/ssl.py in options
     super(SSLContext, SSLContext).options.__set__(self, value) X 100 times...

Is it possible to use requests and grequests in one file?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Yes. Import requests after grequests. Here is an open issue about this.

about 4 years ago · Santiago Trujillo Report

0

This is the only thing that worked for me (Python 3.8.6, a module needed imports of grequests and requests) (source). This should precede all other imports:

from gevent import monkey
def stub(*args, **kwargs):  # pylint: disable=unused-argument
    pass
monkey.patch_all = stub
import grequests
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!