# Not able to connect to App search from Python script

**URL:** <https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 30, 2020, 2:57pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579 "2020-04-30T14:57:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishelini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rishelini/32/47867_2.png) [@rishelini](https://discuss.elastic.co/u/rishelini)\
**Post date:** [April 30, 2020, 2:57pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/1 "2020-04-30T14:57:05Z")

</div>

Hello!  
We have a problem connecting to our App Search engine from python using the elastic\_app\_search library. After creating a client instance with our proper credentials the server is rejecting to output anything. For illustration I am using the get\_schema method.

```auto
from elastic_app_search import Client
client = Client(base_endpoint=base_endpoint,api_key=api_key, use_https=False)
engine_name = "our_engine"
client.get_schema(engine_name) 

```

We get the following error:

```auto
HTTPConnectionPool(host='https', port=...): Max retries exceeded with url: //... /our_engine/schema (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ...>: Failed to establish a new connection: [Errno -2] Name or service not known',))

```

Is there anything we need to adjust in the App search settings to allow it? We should definitely not exceed any limit as we were not connected never before.  
The weird thing is that from javascript the connection works fine.

Thank you!

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 30, 2020, 7:09pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/2 "2020-04-30T19:09:04Z")

</div>

Hello @rishelini

The error tells about the fact the domain cannot be resolved (`Name or service not known`).

The documentation at this link [https://github.com/elastic/app-search-python/blob/master/README.md](https://github.com/elastic/app-search-python/blob/master/README.md)

Can you please check the value of `base_endpoint` doesn't contain `http://` or `https://`?  
Also, does the host where the python code runs has access to the endpoint? Can you try with a `curl`?

---

<div class="post-metadata">

**Author:** ![rishelini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rishelini/32/47867_2.png) [@rishelini](https://discuss.elastic.co/u/rishelini)\
**Post date:** [April 30, 2020, 8:03pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/3 "2020-04-30T20:03:10Z")

</div>

Hello @Luca_Belluccini,

so I removed the `https://` part from the endpoint, that was probably the cause. But ended up with another exception `elastic_app_search.exceptions.NonExistentRecord`. Is it good?

With **curl** I was able to reach the endpoint in `https://` format with response "You are being redirected" to the login page.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 30, 2020, 9:14pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/4 "2020-04-30T21:14:26Z")

</div>

> [@rishelini](#):
>
> so I removed the `https://` part from the endpoint, that was probably the cause. But ended up with another exception `elastic_app_search.exceptions.NonExistentRecord` . Is it good?

I think you managed to connect.

Which one of the methods generated the exception `elastic_app_search.exceptions.NonExistentRecord`?

---

<div class="post-metadata">

**Author:** ![rishelini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rishelini/32/47867_2.png) [@rishelini](https://discuss.elastic.co/u/rishelini)\
**Post date:** [April 30, 2020, 9:26pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/5 "2020-04-30T21:26:09Z")

</div>

The methods I am calling on the Client instance - list\_engines, create\_engine, get\_documents.  
In App Search, everything is set up and the engine whose name I am passing to the client contains data which I put there as a json file. I am pretty sure I am entering right engine name - the one that is displayed in App Search under Engines.

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 30, 2020, 11:48pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/6 "2020-04-30T23:48:44Z")

</div>

Just to clarify:

1. If your `base_endpoint` is HTTPS, set `use_https=True` in the `Client` initialization.

2. If you are using the [SaaS version available on swiftype.com](https://app.swiftype.com/as) of App Search, you should use the version 7.5.x of the client.

3. Checking the code, the only way to get `NonExistentRecord` is when the request returns HTTP 404.

As the library uses `requests` library, if you're using Python 3, you can add this at the beginning of your script to log the requests (from [StackOverflow](https://stackoverflow.com/questions/16337511/log-all-requests-from-the-python-requests-module?rq=1)). Some details will be in `requests.log`, others in `stdout`.

```auto
import requests
import logging
from http.client import HTTPConnection
log = logging.getLogger('urllib3')
log.setLevel(logging.DEBUG)
fh = logging.FileHandler("requests.log")
log.addHandler(fh)
HTTPConnection.debuglevel = 1

```

---

<div class="post-metadata">

**Author:** ![rishelini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rishelini/32/47867_2.png) [@rishelini](https://discuss.elastic.co/u/rishelini)\
**Post date:** [May 1, 2020, 5:57pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/7 "2020-05-01T17:57:55Z")

</div>

1. Yes, I am using this setting  
2 . As for the elastic\_app\_search library, I'm using version 7.6.0.

After I added your script, I found this in the `requests.log`:

```auto
https://my_base_endpoint:443 "GET /engines/our_engine/schema HTTP/1.1" 404 636

```

When I click on this URL it takes me to the login page and after that on the page with schemas.

Still, really don't know where the problem is.

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [May 2, 2020, 12:47am UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/8 "2020-05-02T00:47:46Z")

</div>

What is the result of `client.list_engines(current=1, size=20)`?

Does `our_engine` contains any special character? (I am not able to tell if this is the actual engine name or you've hidden the engine).

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [May 4, 2020, 1:36pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/9 "2020-05-04T13:36:56Z")

</div>

Make sure your base\_endpoint looks something like this, excluding the protocol and including `/api/as/v1`

[77b18391238412934827.app-search.us-east-1.aws.found.io/](http://77b18391238412934827.app-search.us-east-1.aws.found.io/) **api/as/v1**

---

<div class="post-metadata">

**Author:** ![A\_Tran](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@A\_Tran](https://discuss.elastic.co/u/A_Tran)\
**Post date:** [May 5, 2020, 11:51pm UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/10 "2020-05-05T23:51:05Z")

</div>

Now is working!!! thanks!

---

<div class="post-metadata">

**Author:** ![rishelini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rishelini/32/47867_2.png) [@rishelini](https://discuss.elastic.co/u/rishelini)\
**Post date:** [May 6, 2020, 8:20am UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/11 "2020-05-06T08:20:59Z")

</div>

That was the problem!  
Thank you both very much 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:** [June 3, 2020, 8:21am UTC](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579/12 "2020-06-03T08:21:03Z")

</div>

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