23

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)
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
user3871
  • 12,432
  • 33
  • 128
  • 268
  • 1
    as @Wang Rex did, changing from https to http works ,but the correct solution would be [here](https://github.com/gevent/gevent/issues/941) (it worked for me) – Sharath BJ Jul 03 '18 at 10:39
  • switching from https to http doesn't work as a general solution. What if you're beaming about bank details or checks on people's health, passwords, background-checks? – MrMesees Oct 05 '18 at 19:29

5 Answers5

31

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
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
luckydonald
  • 5,976
  • 4
  • 38
  • 58
5

Do not monkey-patch ssl:

from gevent import monkey
monkey.patch_all(ssl=False)
I159
  • 29,741
  • 31
  • 97
  • 132
Vladimir
  • 145
  • 2
  • 9
2

Update:

I figured out that my issue is because I introduced locust in another place of my application, which uses gevent==1.2.2. After I commented out the gevent import statements, this recursion issue was gone. It is worth checking if you have introduced gevent somewhere in your app.


I ran into the same error recently, and haven't found any way to solve this. I had to use http instead of https in my situation, although it's really dangerous.

Rex Wang
  • 368
  • 2
  • 5
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
manna
  • 11
  • 1
  • I was searching for a similar issue and found a [closed issue](https://github.com/spyoungtech/grequests/issues/103) The above solution worked for me – manna Dec 29 '20 at 15:18
  • can't upvote this enough ) it's just, I have uncommented curious_george.patch_all(thread=False, select=False) line – Anatoly Alekseev Apr 04 '21 at 03:12
0

For my case, I use reqto, the solution was to put a try: except: block around it:

    peers = None

    try:
        res = reqto.get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=5)
        peers = res.json()

        if not res.ok or res.status_code >= 400:
            print("WARNING: Cannot fetch peers:", domain)
            update_last_error(domain, res)

    except:
        print("WARNING: Some error during get():", domain)

If this doesn't work for you, you might want to cleanup your ~/.local/lib/python3/site-packages/ directory. Some old remaining files have caused a freezer and that no file was fetched from remote. Caused me a lot of hours to discover it!

Nope, not working! Maybe just pure coincidence!

For my script, I had to import reqto in fba.commands module while it was not referenced there. I mad a separate branch so you can find it out yourself: https://git.mxchange.org/?p=fba.git;a=shortlog;h=refs/heads/broken/missing-import-reqto Just put that said import line in the said file' header where the other import line exist and that code will work!

Roland
  • 184
  • 1
  • 14