# Basic Authentication not working via python client

**URL:** <https://discuss.elastic.co/t/basic-authentication-not-working-via-python-client/301435>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 3, 2022, 7:17pm UTC](https://discuss.elastic.co/t/basic-authentication-not-working-via-python-client/301435 "2022-04-03T19:17:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfinan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tfinan/32/100693_2.png) [@tfinan](https://discuss.elastic.co/u/tfinan)\
**Post date:** [April 3, 2022, 7:17pm UTC](https://discuss.elastic.co/t/basic-authentication-not-working-via-python-client/301435/1 "2022-04-03T19:17:08Z")

</div>

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:

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

```

from this code:

```auto
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.

---

<div class="post-metadata">

**Author:** ![sethmlarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sethmlarson/32/93342_2.png) [@sethmlarson](https://discuss.elastic.co/u/sethmlarson)\
**Post date:** [April 3, 2022, 7:57pm UTC](https://discuss.elastic.co/t/basic-authentication-not-working-via-python-client/301435/2 "2022-04-03T19:57:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tfinan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tfinan/32/100693_2.png) [@tfinan](https://discuss.elastic.co/u/tfinan)\
**Post date:** [April 3, 2022, 9:55pm UTC](https://discuss.elastic.co/t/basic-authentication-not-working-via-python-client/301435/3 "2022-04-03T21:55:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 1, 2022, 9:56pm UTC](https://discuss.elastic.co/t/basic-authentication-not-working-via-python-client/301435/4 "2022-05-01T21:56:10Z")

</div>

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