diff --git a/mercurial_keyring.py b/mercurial_keyring.py --- a/mercurial_keyring.py +++ b/mercurial_keyring.py @@ -240,8 +240,12 @@ class PasswordStore(object): """Physically write to keyring""" keyring = import_keyring() # keyring in general expects unicode. - # Mercurial provides "local" encoding. See #33 - password = encoding.fromlocal(password).decode('utf-8') + # Mercurial provides "local" encoding. See #33. + # py3 adds even more fun as we get already unicode from getpass. + # To handle those quirks, let go through encoding.fromlocal in case we + # got bytestr here, this will handle both normal py2 and emergency py3 cases. + if isinstance(password, bytes): + password = encoding.fromlocal(password).decode('utf-8') try: keyring.set_password( KEYRING_SERVICE, pwdkey, password)