Basic Authentication not working via python client

I have been experimenting with some very simply python code to interact with Elasticsearch. Up
until a couple of days ago, everything was working great. I could add data to an index, read from
the index, search, etc....
However, suddenly today, I am getting this error:

AuthenticationException: AuthenticationException(401, 'security_exception', 'missing authentication credentials for REST request [/albums/_doc/6]')

from this code:

from datetime import datetime
from elasticsearch import Elasticsearch

es = Elasticsearch('http://localhost:9200', basic_auth=("elastic","Elastic"))
resp = es.get(index="albums", id=6)

Not only have I not made any authentication changes on the server, If I do the very same
REST queries via either the Elasticsearch Dev Tool Console, or via Postman, they work just
fine (with the exact same credentials).

I am just getting started using the python client code, so this is really making me pull my
hair out. Any help would be appreciated.

1 Like

Hello! What is the major version of the libary you're using (elasticsearch.__version__)?

If it starts with 7... then you should use http_auth=("username", "password") instead of basic_auth=.... The basic_auth=... parameter was only added in v8.0.0.

1 Like

Thanks, that definitely fixed it, but it is weird, because basic_auth was working fine just a couple of days ago. I did install Elasticsearch-dsl since then, so I am now wondering of I may have already had v8.0 installed, but Elasticsearch-dsl somehow downgraded me to v7?

Thanks for your help.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.