# Python api client connection with proxy

**URL:** <https://discuss.elastic.co/t/python-api-client-connection-with-proxy/319232>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 17, 2022, 5:46pm UTC](https://discuss.elastic.co/t/python-api-client-connection-with-proxy/319232 "2022-11-17T17:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas.queiroz](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lucas.queiroz](https://discuss.elastic.co/u/lucas.queiroz)\
**Post date:** [November 17, 2022, 5:46pm UTC](https://discuss.elastic.co/t/python-api-client-connection-with-proxy/319232/1 "2022-11-17T17:46:17Z")

</div>

Hi use the following class to connect the client to Elastic Cloud running in Azure. The job runs in kubernetes updating my index with some data in a daily basis, and I need to setup the proxy from my organization in order to reach the es endpoint.

```auto
from elasticsearch import Elasticsearch, RequestsHttpConnection # v7.10.0
from elasticsearch.helpers import bulk

class ESManagement:
    def __init__ (self):
        self.es_client = Elasticsearch(
            hosts=os.environ.get('es_endpoint'),
            http_auth=(os.environ.get('es_username'), os.environ.get('es_password')),
            connection_class=MyConnection,
            proxies={'https': os.environ.get('proxy4server'), 'http': os.environ.get('proxy4server')}
        )

    def create_index(self, index: str):
        (...)

    def delete_index(self, index_name):
        (...)

    def index_batch(self, docs):
        (...)

class MyConnection(RequestsHttpConnection):
    def __init__ (self, *args, **kwargs):
        proxies = kwargs.pop('proxies', {})
        super(MyConnection, self). __init__ (*args, **kwargs)
        self.session.proxies = proxies

```

This class works fine running with elasticsearch 7.10.0. Now I want to update to elasticsearch api 8.5.1. I saw the [migration](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/migration.html) page, but it doesn't mention anything about the proxies setup. Does any one have any idea about how to implement some similar code for the new version?

Also I realized that "RequestsHttpConnection" is not available anymore, so I guess the api will be using Urllib3 library everytime, rigth?

---

<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:** [November 17, 2022, 5:46pm UTC](https://discuss.elastic.co/t/python-api-client-connection-with-proxy/319232/2 "2022-11-17T17:46:17Z")

</div>

elasticsearch 7.10 is [EOL](https://www.elastic.co/support/eol) and no longer supported. Please upgrade ASAP.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<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:** [December 15, 2022, 5:46pm UTC](https://discuss.elastic.co/t/python-api-client-connection-with-proxy/319232/3 "2022-12-15T17:46:43Z")

</div>

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