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

[8.0] Allow using http_auth with RequestsHttpNode for custom authentication #1778

Closed
sethmlarson opened this issue Oct 27, 2021 · 6 comments · Fixed by #1944
Closed

[8.0] Allow using http_auth with RequestsHttpNode for custom authentication #1778

sethmlarson opened this issue Oct 27, 2021 · 6 comments · Fixed by #1944

Comments

@sethmlarson
Copy link
Contributor

sethmlarson commented Oct 27, 2021

Using http_auth is deprecated for passing Tuple[str, str] and str but is useful for custom HTTP authentication with the Requests library. For example Kerberos and GSS are possible with this method. To allow for these to continue working we'll continue setting requests.Session.auth = http_auth when used this way.

Reference: #1776 (comment)

@sethmlarson
Copy link
Contributor Author

Work is done on the transport side: elastic/elastic-transport-python#48

@naisanzaa
Copy link

Error importing RequestsHttpConnection:

from elasticsearch import RequestsHttpConnection

Traceback (most recent call last):
  File "/Users/eric/venv/garbage/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-8-6f544e924cdd>", line 1, in <module>
    from elasticsearch import RequestsHttpConnection
ImportError: cannot import name 'RequestsHttpConnection' from 'elasticsearch' (/Users/eric/venv/garbage/lib/python3.9/site-packages/elasticsearch/__init__.py)

elastic-transport==8.0.1
elasticsearch==8.0.0

@sethmlarson
Copy link
Contributor Author

@naisanzaa Transport-layer classes aren't supplied via the elasticsearch package any more, the elastic_transport package is used for multiple packages including elasticsearch. You can find RequestsHttpNode in that package.

@Nour963
Copy link

Nour963 commented Mar 17, 2022

So what is the solution to this problem ?
I'm still having the same issue, with ES 8.1.0
This stackoverflow post has an answer that says to downgrade from python package elasticsearch==8.0.0 to elasticsearch==7.13.4

@sethmlarson
Copy link
Contributor Author

Since there's a lot of interest in this feature, this will be released in 8.2.0 but support is currently merged into main.

tommycahir pushed a commit to tommycahir/python-elasticsearch-ecs-logger that referenced this issue Apr 27, 2022
changed from RequestsHttpConnection to RequestsHttpNode as 'RequestsHttpConnection' was removed from 'elasticsearch' and is replaced with RequestsHttpNode from elastic_transport elastic/elasticsearch-py#1778 (comment)
@james-henry-git
Copy link

So what is the solution to this problem ? I'm still having the same issue, with ES 8.1.0 This stackoverflow post has an answer that says to downgrade from python package elasticsearch==8.0.0 to elasticsearch==7.13.4

FYI, for those struggling with using the requests module in Elasticsearch 8.x is hardly documented well, we shouldn't need to thunk down versions, we just need to tell it to use RequestsHttpNode and set the appropriate variables.

import os
os.environ["https_proxy"] = "http://proxy_name:8080"
from elastic_transport import RequestsHttpNode
from elasticsearch import Elasticsearch
client = Elasticsearch(
    cloud_id = authkeys['cloud_id'], 
    api_key = authkeys['api_key'],
    node_class=RequestsHttpNode,
    )

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

Successfully merging a pull request may close this issue.

4 participants