Crash in python3 with the 'file' backend

Bug #1685547 reported by Jose Manuel Santamaria Lema
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Kubuntu Automation
New
Undecided
Unassigned
python-launchpadlib (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Hi,

I have a program written in python 3 which uses launchpadlib, and it's crashing if it tries to use the 'file' backend:

$ kubuntu-retry-builds -r frameworks -d artful
Logs are activated and are going to be stored in:
/home/santa/kubuntu-retry-builds_logs
If you want to disable this feature, edit your ~/kubuntu-automation.conf
Date started: Sat, 22 Apr 2017 22:52:10 +0200
The authorization page:
 (https://launchpad.net/+authorize-token?oauth_token=qp1rQXkMXWMMj0pQBHgq&allow_permission=DESKTOP_INTEGRATION)
should be opening in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.
Waiting to hear from Launchpad about your decision...
Traceback (most recent call last):
  File "/usr/bin/kubuntu-retry-builds", line 90, in <module>
    lp = Launchpad.login_with("kubuntu-retry-builds", "production")
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 549, in login_with
    credential_save_failed, version)
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 356, in _authorize_token_and_login
    credentials = authorization_engine(credentials, credential_store)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 553, in __call__
    credential_store.save(credentials, self.unique_consumer_id)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 308, in save
    raise e
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 303, in save
    self.do_save(credentials, unique_consumer_id)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 385, in do_save
    'launchpadlib', unique_key, serialized)
  File "/usr/lib/python3/dist-packages/keyring/core.py", line 48, in set_password
    _keyring_backend.set_password(service_name, username, password)
  File "/usr/lib/python3/dist-packages/keyring/backends/file.py", line 87, in set_password
    password_encrypted = self.encrypt(password.encode('utf-8'))
AttributeError: 'bytes' object has no attribute 'encode'

As a workaround I replaced the file.py line in question with:
password_encrypted = self.encrypt(str(password).encode('utf-8'))
and now it works.

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

What is your version of python-keyring (or Ubuntu)?

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

Nevermind. I have asked the upstream developer of python-keyring, and he says that only unicode passwords are supported [1]. Here launchpadlib is trying to save a bytes password, which is a bug. So I am reassigning this to python3-launchpadlib.

Looking at launchpadlib source, the password is automatically generated and then encoded with base64. I am not sure if base64 is still needed (any unicode characters should work; if no, please report a bug and specify the backend used). But in any case, you can easily convert bytes to unicode by using .decode('latin-1') (and then .encode('latin-1') back when reading the password from the keyring).

[1]: https://github.com/jaraco/keyring/issues/275

affects: python-keyring (Ubuntu) → python-launchpadlib (Ubuntu)
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-launchpadlib (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.