Use of RecursionError breaks compatibility with Python 2.7 and 3.4
See original GitHub issueelasticsearch-py
version: 7.13.2
Description of the problem including expected versus actual behavior:
In commit cfdfd5111fd, use of the RecursionError
class was introduced. This class was added in Python 3.5, though.
This causes errors as this under Python 2.7:
def perform_request(
self, method, url, params=None, body=None, timeout=None, ignore=(), headers=None
):
url = self.url_prefix + url
if params:
url = "%s?%s" % (url, urlencode(params))
full_url = self.host + url
start = time.time()
orig_body = body
try:
kw = {}
if timeout:
kw["timeout"] = timeout
# in python2 we need to make sure the url and method are not
# unicode. Otherwise the body will be decoded into unicode too and
# that will fail (#133, #201).
if not isinstance(url, str):
url = url.encode("utf-8")
if not isinstance(method, str):
method = method.encode("utf-8")
request_headers = self.headers.copy()
request_headers.update(headers or ())
if self.http_compress and body:
body = self._gzip_compress(body)
request_headers["content-encoding"] = "gzip"
response = self.pool.urlopen(
method, url, body, retries=Retry(False), headers=request_headers, **kw
)
duration = time.time() - start
raw_data = response.data.decode("utf-8", "surrogatepass")
> except RecursionError:
E NameError: global name 'RecursionError' is not defined
../../../.venv/py2/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py:256: NameError
According to #1295 and setup.py
, Python 2.7 and 3.4 should still be supported, though.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
PEP 606 – Python Compatibility Version
This PEP proposes to add a partial compatibility with old Python versions as a tradeoff to fit both use cases. The main issue...
Read more >Is Python 3.4 backwards compatible for 2.7 programs/libraries?
Minor versions of python are mostly backwards compatible, however major versions do not maintain backwards compatibility.
Read more >Changes — Jinja Documentation (3.0.x)
Drop support for Python 2.6, 3.3, and 3.4. This will be the last version to support Python 2.7 and 3.5. Added a new...
Read more >Release Notes — NumPy v1.16 Manual
This NumPy release is the last one to support Python 2.7 and will be maintained ... For compatibility with the old behavior, use...
Read more >precursion - PyPI
PyPI Python 2.7, 3.4, 3.5, 3.6. precursion – Python module to avoid RecursionError: maximum recursion depth exceeded easily. Usage. Ok, let's ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for looking into this. I guess this hasn’t shown up in the tests because the specific error is not triggered. As far as I understand, the
except
expression is not evaluated unless there actually is an exception to handle.The error is actually easy to trigger by trying to talk to a non-existent server:
Closed in https://github.com/elastic/elasticsearch-py/pull/1609