带有请求的grequest有冲突

沙夫龙

我正在使用grequests python模块调用一些API。我想做两个功能。

  1. 单个请求(使用请求模块)
  2. 多个请求(使用grequests模块)

当我在两个不同文件中使用两个模块时,它可以正常运行,但是当我在同一文件中导入两个模块时,请求模块属于无限递归。

  #!/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;       

如果我调用MultiRequest()->做得好!

但是如果我调用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...

是否可以在一个文件中使用请求和grequest

阿列克谢·阿塔诺夫(Alexey Atanov)

是。grequests之后导入请求这是一个未解决的问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章