Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy support for urllib3 #53

Open
dliappis opened this issue Oct 23, 2018 · 3 comments
Open

Add proxy support for urllib3 #53

dliappis opened this issue Oct 23, 2018 · 3 comments

Comments

@dliappis
Copy link

Currently it is possible to use elasticsearch-py behind a proxy by switching to the requests library, which honors proxy variables [1].

As discussed in elastic/rally#584 (review) it would be awesome to get proxy support for urllib3 as well.

[1] Related issues:

@dliappis
Copy link
Author

FYI @fxdgear

@maharg101
Copy link

+1

@sethmlarson sethmlarson transferred this issue from elastic/elasticsearch-py Dec 2, 2021
@pquentin
Copy link
Member

It's not really practical with urllib3 because in elastic_transport's Urllib3HttpNode uses urllib3's HTTPConnectionPool and HTTPSConnectionPool while proxies are handled at the PoolManager/ProxyManager level which is completely ignored here. However we can easily use requests. The difference with elastic/elasticsearch-py#275 (comment) is that elasticsearch.Elasticsearch now raises a TypeError if we pass it an unknown kwarg, so we hardcode the proxies in CustomHttpNode:

from elastic_transport import RequestsHttpNode
from elasticsearch import Elasticsearch


class CustomHttpNode(RequestsHttpNode):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # I launched an HTTP proxy using `python dummyserver/proxy.py` from the urllib3 code base
        self.session.proxies = {"https": "http://localhost:8888"}


es = Elasticsearch(
    "https://localhost:9200",
    # See https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/connecting.html to get those values
    ssl_assert_fingerprint="725a0b3250ad15c01db1f31d81190490196038e2e51026bc9113ced2b36b0c7c",
    basic_auth=("elastic", "5w6VlIJxgygvweV66epH"),
    node_class=CustomHttpNode,
)
print(es.info().body, indent=2)

The downside of using requests is added complexity and lack of support for full HTTPS proxies (TLS-in-TLS): psf/requests#5665.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants