Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda