The error 401 means that something is wrong with the authentication, the username or the password, you need to check the password and see if it is correct.
Hi,
I have double checked -- everything is correct.
Code is:-
# connect to ES on localhost on port 9200
from ssl import create_default_context
import ssl
# from elasticsearch.connection import create_ssl_context
es = Elasticsearch([{'host': 'localhost', 'port': 9200,'scheme':'https'}],basic_auth=('username', 'password'),
verify_certs=False, ssl_show_warn=True,ca_certs='/home/shivang_ahd1234/cacert.pem') # 'certs/transport.p12'
if es.ping():
print('Connected to ES!')
else:
print('Could not connect!')
# sys.exit()
print("*********************************************************************************");
print(es.info())
error is:
Could not connect!
*********************************************************************************
/home/shivang_ahd1234/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
/home/shivang_ahd1234/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
---------------------------------------------------------------------------
AuthenticationException Traceback (most recent call last)
Cell In [11], line 16
13 # sys.exit()
15 print("*********************************************************************************");
---> 16 print(es.info())
File ~/miniconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/utils.py:414, in _rewrite_parameters.<locals>.wrapper.<locals>.wrapped(*args, **kwargs)
411 except KeyError:
412 pass
--> 414 return api(*args, **kwargs)
File ~/miniconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/__init__.py:2296, in Elasticsearch.info(self, error_trace, filter_path, human, pretty)
2294 __query["pretty"] = pretty
2295 __headers = {"accept": "application/json"}
-> 2296 return self.perform_request( # type: ignore[return-value]
2297 "GET", __path, params=__query, headers=__headers
2298 )
File ~/miniconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/_base.py:321, in BaseClient.perform_request(self, method, path, params, headers, body)
318 except (ValueError, KeyError, TypeError):
319 pass
--> 321 raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
322 message=message, meta=meta, body=resp_body
323 )
325 # 'X-Elastic-Product: Elasticsearch' should be on every 2XX response.
326 if not self._verified_elasticsearch:
327 # If the header is set we mark the server as verified.
AuthenticationException: AuthenticationException(401, 'security_exception', 'unable to authenticate user [username] for REST request [/]')
Please tell me if there is another way to bypass this..
There is no bypass, you are getting authentication error.
What user and password are you using? You need to put them in the basic_auth
option of your code.
basic_auth=('username', 'password')
username
should be the username you are going to use, like elastic
and the password is the password for the elastic
user.
Are you already doing this? From the error log you shared it seems that you are using the literal values of username
and password
instead of the name of your user and its password.
AuthenticationException: AuthenticationException(401, 'security_exception', 'unable to authenticate user [username] for REST request [/]')
The error you are getting is an authentication error, something is wrong, you may not be passing the correct username or password.
Hi,
Thanks a lot. I got my mistake.
I was using the literal string values 'username' and 'password' instead of passing the variable name username and password.
Got the output.
Hi shivang.ahd, after adding security, Did your problem solve? I mean the issues of auto deleting index
Even I am facing same issues. Elasticsearch is deleting my index after every 3 days. PLease help @leandrojmp
Do you have security enambled? Is your cluster open to the internet?