# Unable to access Elasticsearch connected to company server via Python

**URL:** <https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 6, 2023, 7:07am UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288 "2023-06-06T07:07:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyl](https://avatars.discourse-cdn.com/v4/letter/c/dfb087/32.png) [@cyl](https://discuss.elastic.co/u/cyl)\
**Post date:** [June 6, 2023, 7:07am UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288/1 "2023-06-06T07:07:38Z")

</div>

Hi Elastic community! 😃

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](https://us1.discourse-cdn.com/elastic/original/3X/5/f/5f2abd684712feb7a41e5f9db1751b8e6637c113.png)

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)

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

```

Thank you in advance 🌻

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 6, 2023, 9:38am UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288/2 "2023-06-06T09:38:26Z")

</div>

Hi @cyl,

Welcome to the community! 😄 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?

---

<div class="post-metadata">

**Author:** ![cyl](https://avatars.discourse-cdn.com/v4/letter/c/dfb087/32.png) [@cyl](https://discuss.elastic.co/u/cyl)\
**Post date:** [June 6, 2023, 11:10am UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288/3 "2023-06-06T11:10:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 7, 2023, 9:41am UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288/4 "2023-06-07T09:41:52Z")

</div>

Hi @cyl,

No worries at all! You can add the privileges in the user screen from either [defined roles](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/built-in-roles.html) or your own [custom role](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/defining-roles.html) as per the documentation.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/8/a824974d3cc99ea8ac07ba6f815c13abc3346b59.png)

The privileges you need are in the error message.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![cyl](https://avatars.discourse-cdn.com/v4/letter/c/dfb087/32.png) [@cyl](https://discuss.elastic.co/u/cyl)\
**Post date:** [June 29, 2023, 1:09pm UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288/5 "2023-06-29T13:09:01Z")

</div>

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! 🙂

---

<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:** [July 27, 2023, 1:09pm UTC](https://discuss.elastic.co/t/unable-to-access-elasticsearch-connected-to-company-server-via-python/335288/6 "2023-07-27T13:09:37Z")

</div>

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