'"RecursionError: maximum recursion depth exceeded" from ssl.py: `super(SSLContext, SSLContext).options.__set__(self, value)`
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)
Solution 1:[1]
If gevent
is installed, it needs to monkey-patch the python socket
s 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
Solution 2:[2]
Do not monkey patching ssl:
from gevent import monkey
monkey.patch_all(ssl=False)
Solution 3:[3]
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.
Solution 4:[4]
from gevent import monkey as curious_george
# curious_george.patch_all(thread=False, select=False)
def stub(*args, **kwargs): # pylint: disable=unused-argument
pass
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Anthony Sottile |
Solution 2 | Vladimir |
Solution 3 | |
Solution 4 | manna |