Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requests: RecursionError: maximum recursion depth exceeded

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)
like image 782
user3871 Avatar asked Apr 13 '18 15:04

user3871


People also ask

How do you fix maximum recursion depth exceeded?

The “maximum recursion depth exceeded in comparison” error is raised when you try to execute a function that exceeds Python's built in recursion limit. You can fix this error by rewriting your program to use an iterative approach or by increasing the recursion limit in Python.

How do you solve maximum recursion depth exceeded while calling a Python object?

Conclusion. The recursion depth limit in Python is by default 1000 . You can change it using sys. setrecursionlimit() function.

What is the maximum recursion limit?

The recursion limit is usually 1000.

What is a recursion depth?

Abstract. The maximum depth of recursion refers to the number of levels of activation of a procedure which exist during the deepest call of the procedure.


Video Answer


1 Answers

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
like image 152
luckydonald Avatar answered Oct 25 '22 07:10

luckydonald