|
19 | 19 | import gzip |
20 | 20 | import io |
21 | 21 | import logging |
| 22 | +import os |
22 | 23 | import re |
23 | 24 | import warnings |
24 | 25 | from platform import python_version |
|
28 | 29 | except ImportError: |
29 | 30 | import json |
30 | 31 |
|
31 | | -from .. import __versionstr__ |
| 32 | +from .. import __version__, __versionstr__ |
32 | 33 | from ..exceptions import ( |
33 | 34 | HTTP_EXCEPTIONS, |
34 | 35 | ElasticsearchWarning, |
@@ -121,6 +122,13 @@ def __init__( |
121 | 122 | if opaque_id: |
122 | 123 | self.headers["x-opaque-id"] = opaque_id |
123 | 124 |
|
| 125 | + if os.getenv("ELASTIC_CLIENT_APIVERSIONING") == "1": |
| 126 | + self.headers.setdefault( |
| 127 | + "accept", |
| 128 | + "application/vnd.elasticsearch+json;compatible-with=%s" |
| 129 | + % (str(__version__[0]),), |
| 130 | + ) |
| 131 | + |
124 | 132 | self.headers.setdefault("content-type", "application/json") |
125 | 133 | self.headers.setdefault("user-agent", self._get_default_user_agent()) |
126 | 134 |
|
@@ -248,7 +256,7 @@ def perform_request( |
248 | 256 | def log_request_success( |
249 | 257 | self, method, full_url, path, body, status_code, response, duration |
250 | 258 | ): |
251 | | - """ Log a successful API call. """ |
| 259 | + """Log a successful API call.""" |
252 | 260 | # TODO: optionally pass in params instead of full_url and do urlencode only when needed |
253 | 261 |
|
254 | 262 | # body has already been serialized to utf-8, deserialize it for logging |
@@ -278,7 +286,7 @@ def log_request_fail( |
278 | 286 | response=None, |
279 | 287 | exception=None, |
280 | 288 | ): |
281 | | - """ Log an unsuccessful API call. """ |
| 289 | + """Log an unsuccessful API call.""" |
282 | 290 | # do not log 404s on HEAD requests |
283 | 291 | if method == "HEAD" and status_code == 404: |
284 | 292 | return |
@@ -307,7 +315,7 @@ def log_request_fail( |
307 | 315 | logger.debug("< %s", response) |
308 | 316 |
|
309 | 317 | def _raise_error(self, status_code, raw_data): |
310 | | - """ Locate appropriate exception and raise it. """ |
| 318 | + """Locate appropriate exception and raise it.""" |
311 | 319 | error_message = raw_data |
312 | 320 | additional_info = None |
313 | 321 | try: |
|
0 commit comments