Reputation: 12718
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)
Upvotes: 30
Views: 24122
Reputation: 11214
Also check for truststore usage nowadays, which also patches SSL-handling code and can also trigger these errors.
Upvotes: 0
Reputation: 4364
This max-recursion error arose in the context of a Flask app when I upgraded the requests
library to version 2.32.2. The app seemed to work fine but my automated tests started failing. I took the suggestion offered above and extended my project's conftest.py
file with the gevent
import/patch_all() lines. Then the problem no longer occurred when running tox
. Hope this helps someone out there.
Upvotes: 1
Reputation: 304
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!
Upvotes: 0
Reputation: 145
Do not monkey-patch ssl:
from gevent import monkey
monkey.patch_all(ssl=False)
Upvotes: 5
Reputation: 11
from gevent import monkey as curious_george
# curious_george.patch_all(thread=False, select=False)
def stub(*args, **kwargs): # pylint: disable=unused-argument
pass
Upvotes: 1
Reputation: 6886
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
Upvotes: 34
Reputation: 458
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.
Upvotes: 3