I am using grequests python module to call some APIs. I want to make two functions.
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?
Yes. Import requests after grequests. Here is an open issue about this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With