请求:RecursionError:超过最大递归深度 [英] requests: RecursionError: maximum recursion depth exceeded

查看:101
本文介绍了请求:RecursionError:超过最大递归深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<块引用>

服务器:Windows 10

Python: 3.6.5

请求:2.18.4

Pentaho:8.0

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

<预><代码>>>>进口请求>>>response = requests.get(url, headers=headers)>>>json = response.json()>>>打印(json){'d': {'results': [{'_ ...

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

<块引用>

递归错误:超过最大递归深度

完整日志:

2018/04/13 15:02:17 - Get SP Doc List.0 - 错误(版本 8.0.0.0-28,从 2017-11-05 07.27.50 构建 8.0.0.0-28 by buildguy) : 意外的错误2018/04/13 15:02:17 - 获取 SP Doc List.0 - 错误(版本 8.0.0.0-28,buildguy 从 2017-11-05 07.27.50 构建 8.0.0.0-28):org.pentaho.di.core.exception.KettleException:2018/04/13 15:02:17 - 获取 SP Doc List.0 - 回溯(最近一次通话):文件C:\Users\ADMINI~1\AppData\Local\Temp\2\pyServer.py",第 299 行,在 execute_scriptexec(脚本,_global_env)文件<string>",第 16 行,位于 <module>文件C:\Program Files\Python36\lib\site-packages\requests\api.py",第 72 行,在 get返回请求('get', url, params=params, **kwargs)文件C:\Program Files\Python36\lib\site-packages\requests\api.py",第 58 行,在请求中返回 session.request(method=method, url=url, **kwargs)文件C:\Program Files\Python36\lib\site-packages\requests\sessions.py",第 508 行,在请求中resp = self.send(prep, **send_kwargs)文件C:\Program Files\Python36\lib\site-packages\requests\sessions.py",第 618 行,发送r = 适配器.发送(请求,**kwargs)文件C:\Program Files\Python36\lib\site-packages\requests\adapters.py",第 440 行,发送超时=超时文件C:\Program Files\Python36\lib\site-packages\urllib3\connectionpool.py",第 601 行,在 urlopen分块=分块)_make_request 中的文件C:\Program Files\Python36\lib\site-packages\urllib3\connectionpool.py",第 346 行self._validate_conn(conn)文件C:\Program Files\Python36\lib\site-packages\urllib3\connectionpool.py",第 850 行,在 _validate_conn连接.connect()文件C:\Program Files\Python36\lib\site-packages\urllib3\connection.py",第 314 行,在连接中cert_reqs=resolve_cert_reqs(self.cert_reqs),文件C:\Program Files\Python36\lib\site-packages\urllib3\util\ssl_.py",第 269 行,在 create_urllib3_contextcontext.options |= 选项文件C:\Program Files\Python36\lib\ssl.py",第 465 行,选项中super(SSLContext, SSLContext).options.__set__(self, value)文件C:\Program Files\Python36\lib\ssl.py",第 465 行,选项中super(SSLContext, SSLContext).options.__set__(self, value)文件C:\Program Files\Python36\lib\ssl.py",第 465 行,选项中super(SSLContext, SSLContext).options.__set__(self, value)[上一行重复了 322 次以上]RecursionError:超过最大递归深度

脚本:

导入请求导入json# 按文件名url = "https://myco.sharepoint.com/teams/dg/l/_api/web/lists/GetByTitle('eRetail%20Data%20Sources')/items?..."authtoken = "Bearer eyJ..."标题 = {"Content-Type": "application/json;odata=verbose","接受": "application/json;odata=verbose",授权":authtoken}response = requests.get(url, headers=headers)json = response.json()打印('============================)打印(json)

解决方案

如果安装了gevent,需要对python的sockets进行monkey-patch才能配合(见文档这个 github 问题).

因此 gevent.monkey.patch_all() 要么丢失,要么没有及时调用.

# 在脚本的开头导入 gevent.monkeygevent.monkey.patch_all()# 下面的所有其他内容,例如进口请求

I am using Python 3.6.5 on the following remote server setup:

Server: Windows 10

Python: 3.6.5

Requests: 2.18.4

Pentaho: 8.0

When I run request.get against URLs in the server's command prompt, it gets the JSON as expected:

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

However when I run the same script in CPython for Pentaho 8.0, I get

RecursionError: maximum recursion depth exceeded

Full log:

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

Script:

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)

解决方案

If gevent is installed, it needs to monkey-patch the python sockets to cooperate (see documentation or this github issue).

Therefore gevent.monkey.patch_all() is either missing or not called early enough.

# at the beginning of the script
import gevent.monkey
gevent.monkey.patch_all()

# all the other stuff below, like for example
import requests

这篇关于请求:RecursionError:超过最大递归深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆