DavidMuller/aws-requests-auth

TypeError when initialising es_client

Closed this issue · 1 comments

Following the example in readme, I tried creating es_client object as follows:

es_host = "search-XXXXX-YYYYYYYYYYY.us-west-2.es.amazonaws.com"
auth = AWSRequestsAuth(
    aws_host=es_host,
    aws_region="us-west-2",
    aws_service="es",
    **get_credentials()
)
es = Elasticsearch(
    host=es_host,
    port=443,    # also tried port=80, same error
    connect_class=RequestsHttpConnection,
    http_auth=auth
)

However, the above results in a TypeError being raised with the following traceback:

Traceback (most recent call last):
  File "utils/wrappers/elastic.py", line 41, in <module>
    http_auth=auth
  File "/home/hjpotter92/.virtualenvs/venv/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 171, in __init__
    self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
  File "/home/hjpotter92/.virtualenvs/venv/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 108, in __init__
    self.set_connections(hosts)
  File "/home/hjpotter92/.virtualenvs/venv/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 161, in set_connections
    connections = map(_create_connection, hosts)
  File "/home/hjpotter92/.virtualenvs/venv/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 160, in _create_connection
    return self.connection_class(**kwargs)
  File "/home/hjpotter92/.virtualenvs/venv/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 57, in __init__
    self.headers.update(urllib3.make_headers(basic_auth=http_auth))
  File "/home/hjpotter92/.virtualenvs/venv/local/lib/python2.7/site-packages/urllib3/util/request.py", line 65, in make_headers
    b64encode(b(basic_auth)).decode('utf-8')
  File "/usr/lib/python2.7/base64.py", line 54, in b64encode
    encoded = binascii.b2a_base64(s)[:-1]
TypeError: b2a_base64() argument 1 must be convertible to a buffer, not AWSRequestsAuth

I am using

aws-requests-auth==0.3.3
boto3==1.4.5
elasticsearch==5.3.0

Sorry. The error was because I was initialising el_client with connect_class parameter, instead of connection_class. Changing to the following fixed this:

es = Elasticsearch(
    host=es_host,
    port=443,    # also tried port=80, same error
    connection_class=RequestsHttpConnection,
    http_auth=auth
)