# ESRE class - Python elasticsearch.BadRequestError

**URL:** <https://discuss.elastic.co/t/esre-class-python-elasticsearch-badrequesterror/379540>\
**Category:** Elastic Training\
**Created:** [June 26, 2025, 3:21pm UTC](https://discuss.elastic.co/t/esre-class-python-elasticsearch-badrequesterror/379540 "2025-06-26T15:21:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbieWill](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@newbieWill](https://discuss.elastic.co/u/newbieWill)\
**Post date:** [June 26, 2025, 3:21pm UTC](https://discuss.elastic.co/t/esre-class-python-elasticsearch-badrequesterror/379540/1 "2025-06-26T15:21:47Z")

</div>

Course: Elasticsearch Relevance Engine (ESRE) Engineer  
Version: 8.11.1  
Question: Python Elasticsearch error

Hello, I am trying to work through the ESRE class and am stuck at Lab 3.1-1

When I try to run this code:

```auto
#test-elasticsearch.py
from elasticsearch import Elasticsearch

es = Elasticsearch (
  "https://localhost:9200",
  basic_auth = ("elastic", "nonprodpwd"),
  verify_certs = False
)

print(es.info())

```

I get the following error:

```auto
elastic@ip-172-31-38-174:~/apps/langchain-apps$ python test-elasticsearch.py 
Traceback (most recent call last):
  File "test-elasticsearch.py", line 10, in <module>
    print(es.info())
  File "/home/elastic/.local/lib/python3.8/site-packages/elasticsearch/_sync/client/utils.py", line 415, in wrapped
    return api(*args, **kwargs)
  File "/home/elastic/.local/lib/python3.8/site-packages/elasticsearch/_sync/client/ __init__.py", line 2991, in info
    return self.perform_request( # type: ignore[return-value]
  File "/home/elastic/.local/lib/python3.8/site-packages/elasticsearch/_sync/client/_base.py", line 271, in perform_request
    response = self._perform_request(
  File "/home/elastic/.local/lib/python3.8/site-packages/elasticsearch/_sync/client/_base.py", line 351, in _perform_request
    raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.BadRequestError: BadRequestError(400, 'media_type_header_exception', 'Invalid media-type value on headers [Content-Type, Accept]', Accept version must be either version 8 or 7, but found 9. Accept=application/vnd.elasticsearch+json; compatible-with=9)
elastic@ip-172-31-38-174:~/apps/langchain-apps$

```

Any help would be appreciated. Thank you! -will

---

<div class="post-metadata">

**Author:** ![Tortoise](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tortoise/32/147587_2.png) [@Tortoise](https://discuss.elastic.co/u/Tortoise)\
**Post date:** [June 27, 2025, 4:22am UTC](https://discuss.elastic.co/t/esre-class-python-elasticsearch-badrequesterror/379540/2 "2025-06-27T04:22:29Z")

</div>

Hello @newbieWill ,

Welcome to the community!!

As per the error **"elasticsearch.BadRequestError: BadRequestError(400, 'media\_type\_header\_exception', 'Invalid media-type value on headers [Content-Type, Accept]', Accept version must be either version 8 or 7, but found 9. Accept=application/vnd.elasticsearch+json; compatible-with=9)"**

We can perform below steps :

`pip uninstall elasticsearch`

Once uninstalled install 8.x :

`pip install elasticsearch==8.18.1`

Now try the same command to connect :

`python test-elasticsearch.py`

Thanks!!

---

<div class="post-metadata">

**Author:** ![newbieWill](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@newbieWill](https://discuss.elastic.co/u/newbieWill)\
**Post date:** [July 10, 2025, 11:48pm UTC](https://discuss.elastic.co/t/esre-class-python-elasticsearch-badrequesterror/379540/3 "2025-07-10T23:48:32Z")

</div>

Thanks - That worked!

Sorry for the delayed response 🙂
