Unable to access Elasticsearch connected to company server via Python

Hi Elastic community! :smiley:

I have just started using Elastic and Kibana as my company has opted for this tech stack to store much of our data. To analyse the data, I would prefer the use of Python, and hence have been trying to extract data with the Elasticsearch Python Client, but I can’t seem to do so. I suspect it is due to login credentials, but I have searched high and low for work-arounds but to no avail, would really appreciate any help I can get here! I keep running into this when I try to debug or try to look for the nodes connected:

image

This is how my Python code looks like but I am not sure where in the code I can include credentials as I have done so with the basic_auth argument (XXX is now my username and YYY is the password) but still get a ConnectionError (Timeout). Just in case this is the issue, how do I determine the host if it's a company shared portal? (ie. different users have access to the same data and visualisations)

es = Elasticsearch('https://company-host-name:9200', 
                   basic_auth=("XXX", 'YYY'))
es.ping() # returns False

Thank you in advance :sunflower:

Hi @cyl,

Welcome to the community! :smile: For future issues if you could share the error message as text that would be great as the image is a bit difficult to read.

I'm not sure which versions of Python and Elasticsearch you are using. But it looks to me from the error message that the the username you have specified in the basic_auth method doesn't have the required privileges for the operation you are trying to perform.

Are you able to configure the permissions required for that username in Stack Management to add the required permissions?

Hi Carly,

Thanks for your swift reply, I'll be sure to post the error message as text in future! I am using Python 3.10.9 and I am using Elasticsearch 8.8.0. I tried to go to Stack Management to add the permissions but I am unable to find the fields, please let me know how I can go about it!

Hi @cyl,

No worries at all! You can add the privileges in the user screen from either defined roles or your own custom role as per the documentation.

The privileges you need are in the error message.

Hope that helps!

1 Like

Hi Carly,

Apologies for the late response, this helped! Turns out it was also a firewall issue, so when access was granted it all worked.

Thank you for your kind assistance! :slight_smile:

1 Like

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