question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of RecursionError breaks compatibility with Python 2.7 and 3.4

See original GitHub issue

elasticsearch-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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcSchmitzercommented, Jun 23, 2021

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:

from elasticsearch.client import Elasticsearch
client = Elasticsearch("http://localhost:9", max_retries=0)  # nothing listens on this port
client.indices.stats("_all")
0reactions
sethmlarsoncommented, Jun 25, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found