【问题标题】:requests: RecursionError: maximum recursion depth exceeded请求:RecursionError:超出最大递归深度
【发布时间】:2018-09-24 00:01:30
【问题描述】:

我在以下远程服务器设置上使用 Python 3.6.5:

服务器:Windows 10

Python:3.6.5

请求:2.18.4

Pentaho:8.0

当我在服务器的命令提示符中针对 URL 运行 request.get 时,它会按预期获取 JSON:

>>> import requests
>>> response = requests.get(url, headers=headers)
>>> json = response.json()
>>> print(json)
{'d': {'results': [{'_ ... 

但是,当我在 CPython 中为 Pentaho 8.0 运行相同的脚本时,我得到了

RecursionError: 超出最大递归深度

完整日志:

2018/04/13 15:02:17 - Get SP Doc List.0 - ERROR (version 8.0.0.0-28, build 8.0.0.0-28 from 2017-11-05 07.27.50 by buildguy) : Unexpected error
    2018/04/13 15:02:17 - Get SP Doc List.0 - ERROR (version 8.0.0.0-28, build 8.0.0.0-28 from 2017-11-05 07.27.50 by buildguy) : org.pentaho.di.core.exception.KettleException: 
    2018/04/13 15:02:17 - Get SP Doc List.0 - Traceback (most recent call last):
      File "C:\Users\ADMINI~1\AppData\Local\Temp\2\pyServer.py", line 299, in execute_script
        exec (script, _global_env)
      File "<string>", line 16, in <module>
      File "C:\Program Files\Python36\lib\site-packages\requests\api.py", line 72, in get
        return request('get', url, params=params, **kwargs)
      File "C:\Program Files\Python36\lib\site-packages\requests\api.py", line 58, in request
        return session.request(method=method, url=url, **kwargs)
      File "C:\Program Files\Python36\lib\site-packages\requests\sessions.py", line 508, in request
        resp = self.send(prep, **send_kwargs)
      File "C:\Program Files\Python36\lib\site-packages\requests\sessions.py", line 618, in send
        r = adapter.send(request, **kwargs)
      File "C:\Program Files\Python36\lib\site-packages\requests\adapters.py", line 440, in send
        timeout=timeout
      File "C:\Program Files\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
        chunked=chunked)
      File "C:\Program Files\Python36\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
        self._validate_conn(conn)
      File "C:\Program Files\Python36\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
        conn.connect()
      File "C:\Program Files\Python36\lib\site-packages\urllib3\connection.py", line 314, in connect
        cert_reqs=resolve_cert_reqs(self.cert_reqs),
      File "C:\Program Files\Python36\lib\site-packages\urllib3\util\ssl_.py", line 269, in create_urllib3_context
        context.options |= options
      File "C:\Program Files\Python36\lib\ssl.py", line 465, in options
        super(SSLContext, SSLContext).options.__set__(self, value)
      File "C:\Program Files\Python36\lib\ssl.py", line 465, in options
        super(SSLContext, SSLContext).options.__set__(self, value)
      File "C:\Program Files\Python36\lib\ssl.py", line 465, in options
        super(SSLContext, SSLContext).options.__set__(self, value)
      [Previous line repeated 322 more times]
    RecursionError: maximum recursion depth exceeded

脚本:

import requests
import json


# By Filename
url = "https://myco.sharepoint.com/teams/dg/l/_api/web/lists/GetByTitle('eRetail%20Data%20Sources')/items?..."

authtoken = "Bearer eyJ..."

headers = {
    "Content-Type": "application/json;odata=verbose",
    "Accept": "application/json;odata=verbose",
    "Authorization": authtoken
}

response = requests.get(url, headers=headers)

json = response.json()
print('===========================')
print(json)

【问题讨论】:

  • 正如@Wang Rex 所做的那样,从 https 更改为 http 有效,但正确的解决方案是 here(它对我有用)
  • 从 https 切换到 http 不是通用解决方案。如果您对银行详细信息或对人们的健康、密码、背景调查的检查感到高兴怎么办?

标签: python-3.x python-requests windows-10 pentaho pentaho-spoon


【解决方案1】:
from gevent import monkey as curious_george
# curious_george.patch_all(thread=False, select=False)
def stub(*args, **kwargs):  # pylint: disable=unused-argument
    pass

【讨论】:

  • 我正在搜索类似的问题,发现closed issue上述解决方案对我有用
  • 对此赞不绝口)只是,我没有注释掉好奇乔治.patch_all(thread=False, select=False) 行
【解决方案2】:

不要随意修补 ssl:

from gevent import monkey
monkey.patch_all(ssl=False)

【讨论】:

    【解决方案3】:

    如果安装了gevent,则需要对python sockets 进行猴子补丁才能配合(参见documentationthis github issue)。

    因此,gevent.monkey.patch_all() 要么丢失,要么调用得不够早。

    # at the beginning of the script
    import gevent.monkey
    gevent.monkey.patch_all()
    
    # all the other stuff below, like for example
    import requests
    

    【讨论】:

      【解决方案4】:

      更新:

      我发现我的问题是因为我在我的应用程序的另一个地方引入了 locust,它使用 gevent==1.2.2。在我注释掉 gevent import 语句后,这个递归问题就消失了。值得检查一下您是否在应用中的某处引入了 gevent。


      我最近遇到了同样的错误,但还没有找到解决这个问题的方法。在我的情况下,我不得不使用 http 而不是 https,尽管它确实危险

      【讨论】:

        猜你喜欢
        • 2017-03-24
        • 2020-10-08
        • 2020-07-13
        • 2019-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-23
        • 2019-04-18
        相关资源
        最近更新 更多