# Issues connecting to App Search hosted on Elasticsearch service through Python API

**URL:** <https://discuss.elastic.co/t/issues-connecting-to-app-search-hosted-on-elasticsearch-service-through-python-api/236975>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [June 13, 2020, 10:45am UTC](https://discuss.elastic.co/t/issues-connecting-to-app-search-hosted-on-elasticsearch-service-through-python-api/236975 "2020-06-13T10:45:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coding\_martian](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@coding\_martian](https://discuss.elastic.co/u/coding_martian)\
**Post date:** [June 13, 2020, 10:45am UTC](https://discuss.elastic.co/t/issues-connecting-to-app-search-hosted-on-elasticsearch-service-through-python-api/236975/1 "2020-06-13T10:45:15Z")

</div>

I'm trying to index a document on my App Search Instance running on Elasticsearch Service, using the python API.

My code is as follows

```auto
    from elastic_app_search import Client
    client = Client(
        base_endpoint='https://<redacted>.app-search.eastus2.azure.elastic-cloud.com/api/as/v1/',
        api_key='private-<redacted>',
        use_https=True
    )

    engine_name = '<redacted>'

    def indexDoc(doc):
        return client.index_document(engine_name, doc)

    def main():
        doc = {
            "title": "Test",
            "text": "This worked. Woohoo!"
        }
        print(indexDoc(doc))

    if __name__ == ' __main__':
        main()

```

This yielded the following error:

```auto

    Traceback (most recent call last):
      File "/Users/hari/.pyenv/versions/3.8.2/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
        conn = connection.create_connection(
      File "/Users/hari/.pyenv/versions/3.8.2/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
        for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
      File "/Users/hari/.pyenv/versions/3.8.2/lib/python3.8/socket.py", line 918, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 8] nodename nor servname provided, or not known

```

This error is printed several times, followed by:

```auto
    requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //<redacted>/app-search.eastus2.azure.elastic-cloud.com/api/as/v1//engines/<redacted engine-name>/documents (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10a64c400>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

```

I tried a non https version of this code:

```auto
    client = Client(
    base_endpoint='4e9d28aa6be4481499db518c9f094532.app-search.eastus2.azure.elastic-cloud.com/api/as/v1/',
    api_key='private-ztxmrx3ppvk17pezdkn8iien',
    use_https=False
)

```

Running this, I get multiple errors which look like:

```auto
    requests.exceptions.ConnectionError: HTTPConnectionPool(host='<redacted>.app-search.eastus2.azure.elastic-cloud.com', port=80): Max retries exceeded with url: /api/as/v1//engines/<redacted engine name>/documents (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10e6b72b0>: Failed to establish a new connection: [Errno 60] Operation timed out'))

```

I would ideally like to connect to App Search in HTTPS and index my document. How do I do this?

---

<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:** [June 17, 2020, 3:30pm UTC](https://discuss.elastic.co/t/issues-connecting-to-app-search-hosted-on-elasticsearch-service-through-python-api/236975/2 "2020-06-17T15:30:05Z")

</div>

Make sure you exclude the protocol from "base\_endpoint".

> [@Not able to connect to App search from Python script](https://discuss.elastic.co/t/not-able-to-connect-to-app-search-from-python-script/230579):
>
> 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. 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: HTTPConnectionPool(host='h…

> [@Where is the host identifier?](https://discuss.elastic.co/t/where-is-the-host-identifier/230779/9):
>
> Im just trying to connect by python following the git example, but im getting an error: from elastic\_app\_search import Client import requests import jwt client = Client(base\_endpoint='[https://20becbeexxxx.app-search.us-east-1.aws.found.io/api/as/v1](https://20becbeexxxx.app-search.us-east-1.aws.found.io/api/as/v1)', api\_key='private-xxxx', use\_https=True) engine\_name = 'dequienescl' document = { 'id': 'INscMGmhmX4', 'body': 'A wonderful video of a magnificent cat.' } client.index\_document(engine\_name, document) {'id': 'INscMGmhmX4'}

---

<div class="post-metadata">

**Author:** ![coding\_martian](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@coding\_martian](https://discuss.elastic.co/u/coding_martian)\
**Post date:** [June 17, 2020, 7:31pm UTC](https://discuss.elastic.co/t/issues-connecting-to-app-search-hosted-on-elasticsearch-service-through-python-api/236975/3 "2020-06-17T19:31:10Z")

</div>

That fixed my problem!

I did try excluding the protocol in the past, but I would also set use\_https=false.

The key is to exclude protocol and set use\_https=true

---

<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 15, 2020, 7:31pm UTC](https://discuss.elastic.co/t/issues-connecting-to-app-search-hosted-on-elasticsearch-service-through-python-api/236975/4 "2020-07-15T19:31:13Z")

</div>

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