Skip to content

Invalid media-type value on headers [Content-Type, Accept] on all calls in v9.0.0 #2923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
moh3nhadavi opened this issue Apr 15, 2025 · 7 comments

Comments

@moh3nhadavi
Copy link

Hello,
I define my client as follows:

self.es = AsyncElasticsearch(
    cloud_id=config["cloud_id"],
    basic_auth=(
        config["username"],
        config["password"],
    ),
    http_compress=True,
    request_timeout=60,
)

Since I have installed the v9.0.0 version of Elasticsearch, I get

BadRequestError(400, 'media_type_header_exception', 'Invalid media-type value on headers [Content-Type, Accept]')

on all the requests. I also tried to add

{
    "Accept": "application/json",
    "Content-Type": "application/json"
}

in the header. But it didn't work.

Does anyone have any idea how to fix this bug?

@moh3nhadavi moh3nhadavi changed the title Invalid media-type value on headers [Content-Type, Accept] on all calls Invalid media-type value on headers [Content-Type, Accept] on all calls in v9.0.0 Apr 15, 2025
@aymentil
Copy link

Hi,

Same problem for me it was working until 8.18.0 but after is not working anymore .

@miguelgrinberg
Copy link
Contributor

@moh3nhadavi @aymentil What version of Elasticsearch are you running this against? We suspect this happens because you are using the 9.0.0 client to connect to a 8.x Elasticsearch server. Can you please confirm?

@moh3nhadavi
Copy link
Author

@miguelgrinberg Hello, Thanks for replying.
I realized I have elastic-transport==8.17.1 and elasticsearch==9.0.0 installed. I checked on GitHub; there is an elastic-transport v9 on Git, but it has not been published on PyPI. Do you think this is the issue?

@miguelgrinberg
Copy link
Contributor

@moh3nhadavi I need to know what server version you have. We have not released a 9.0 version of elastic-transport. The latest 8.x release should work just fine with ES 9. But you need to use a version 9 server. Can you confirm what version is your server please?

@moh3nhadavi
Copy link
Author

@miguelgrinberg I got your point. Indeed, it is v8.13.4, not ES 9.

@miguelgrinberg
Copy link
Contributor

@moh3nhadavi Okay, good. You will need to upgrade the client and the server to 9 at the same time, or else upgrade the server first and then the client. The 9.0 client does not offer compatibility with the 8.x or older servers.

@moh3nhadavi
Copy link
Author

@miguelgrinberg Clear, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants