elasticsearch-py icon indicating copy to clipboard operation
elasticsearch-py copied to clipboard

Passwords in basic auth can't be non latin-1

Open gingerwizard opened this issue 6 years ago • 3 comments

When passing basic auth headers the client calls:

b64encode(b(basic_auth)).decode('utf-8') via the urllib3 request package.

Here b is defined as

def b(s):
        return s.encode("latin-1")

This causes any non latin-1 to be encoded incorrectly and prevents auth.

gingerwizard avatar Nov 04 '19 20:11 gingerwizard

Current solution is to use a custom class for the auth pair i.e.


class UTFBasicAuth():

    def __init__(self, username, password):
        self.username = username
        self.password = password

    def encode(self, encoding):
        return ('%s:%s' % (self.username, self.password)).encode('utf-8')

gingerwizard avatar Nov 04 '19 20:11 gingerwizard

@gingerwizard thanks for opening this issue, I was able to reproduce this by adding a user with an á character in the password and then attempting to make a request via the elasticsearch-py library. I'll do some more investigation to come up with a suitable fix.

alexk307 avatar Feb 07 '20 15:02 alexk307