[Bug 1471927] Re: AccessToken.from_string() crashes on python3
Dimitri John Ledkov
launchpad at surgut.co.uk
Tue Feb 7 10:36:00 UTC 2017
Attempted to login using python3 on existing client and got the
traceback:
/usr/lib/python3/dist-packages/launchpadlib/credentials.py in from_string(cls, query_string)
249 """Create and return a new `AccessToken` from the given string."""
250 params = cgi.parse_qs(query_string, keep_blank_values=False)
--> 251 key = params['oauth_token']
252 assert len(key) == 1, (
253 "Query string must have exactly one oauth_token.")
KeyError: 'oauth_token'
Upgraded to:
Get:1 http://archive.ubuntu.com/ubuntu xenial-proposed/main amd64 python3-launchpadlib all 1.10.3-3ubuntu0.1 [36.5 kB]
And that traceback is gone.
However, keyring integration is still broken:
In [1]: from launchpadlib.launchpad import Launchpad
In [2]: lp = Launchpad.login_with('just testing', 'production', version='devel')
The authorization page:
(https://launchpad.net/+authorize-token?oauth_token=G81S4r3H7ppz29Zr4z6r&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...
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-469be45530f4> in <module>()
----> 1 lp = Launchpad.login_with('just testing', 'production', version='devel')
/usr/lib/python3/dist-packages/launchpadlib/launchpad.py in login_with(cls, application_name, service_root, launchpadlib_dir, timeout, proxy_info, authorization_engine, allow_access_levels, max_failed_attempts, credentials_file, version, consumer_name, credential_save_failed, credential_store)
542 cache_path, timeout, proxy_info, authorization_engine,
543 allow_access_levels, credential_store,
--> 544 credential_save_failed, version)
545
546 @classmethod
/usr/lib/python3/dist-packages/launchpadlib/launchpad.py in _authorize_token_and_login(cls, consumer_name, service_root, cache, timeout, proxy_info, authorization_engine, allow_access_levels, credential_store, credential_save_failed, version)
349 # They're not there. Acquire new credentials using the
350 # authorization engine.
--> 351 credentials = authorization_engine(credentials, credential_store)
352 else:
353 # We acquired credentials. But, the application name
/usr/lib/python3/dist-packages/launchpadlib/credentials.py in __call__(self, credentials, credential_store)
550 return None
551 # save() invokes the callback on failure.
--> 552 credential_store.save(credentials, self.unique_consumer_id)
553 return credentials
554
/usr/lib/python3/dist-packages/launchpadlib/credentials.py in save(self, credentials, unique_consumer_id)
305 except Exception as e:
306 if self.credential_save_failed is None:
--> 307 raise e
308 self.credential_save_failed()
309 return credentials
/usr/lib/python3/dist-packages/launchpadlib/credentials.py in save(self, credentials, unique_consumer_id)
300 """
301 try:
--> 302 self.do_save(credentials, unique_consumer_id)
303 except EXPLOSIVE_ERRORS:
304 raise
/usr/lib/python3/dist-packages/launchpadlib/credentials.py in do_save(self, credentials, unique_key)
382 serialized = self.B64MARKER + b64encode(serialized)
383 keyring.set_password(
--> 384 'launchpadlib', unique_key, serialized)
385
386 def do_load(self, unique_key):
/usr/lib/python3/dist-packages/keyring/core.py in set_password(service_name, username, password)
46 """Set password for the user in the specified service.
47 """
---> 48 _keyring_backend.set_password(service_name, username, password)
49
50
/usr/lib/python3/dist-packages/keyring/backends/file.py in set_password(self, service, username, password)
85
86 # encrypt the password
---> 87 password_encrypted = self.encrypt(password.encode('utf-8'))
88 # encode with base64
89 password_base64 = base64.encodestring(password_encrypted).decode()
AttributeError: 'bytes' object has no attribute 'encode'
** Tags removed: verification-needed
** Tags added: verification-done
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to python-launchpadlib in Ubuntu.
https://bugs.launchpad.net/bugs/1471927
Title:
AccessToken.from_string() crashes on python3
Status in launchpadlib :
Fix Released
Status in python-launchpadlib package in Ubuntu:
Fix Released
Status in python-launchpadlib source package in Xenial:
Fix Committed
Bug description:
[Impact]
* Unable to renew/relogin with a new oauth token, using python3 scripts
* python2 APIs work (because python2 does not care about str vs bytes)
[Test Case]
* Attempt login_with() using python3 and an expired/invalid existing token
* Relogin should be successful, without crashing scripts
[Regression Potential]
* No change in behaviour on python2 (which is what used by reverse dependencies)
* this is a backport to fix python3 behaviour, for all the newly ported maintainance scripts in python3 that prefer to run on "stable" systems
[Other Info]
* Well tested in later releases, and with users running from trunk.
* I believe this still is not published in the cheeseshop.
[Original bug report]
Trying to use Launchpad.login_with() on python3, after fixing the
earlier bug yields this issue:
Traceback (most recent call last):
File "./foo.py", line 31, in <module>
lb = launchpad.projects[project]
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 1001, in __getitem__
shim_resource._ensure_representation()
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 382, in _ensure_representation
representation = self._root._browser.get(self._wadl_resource)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 436, in get
response, content = self._request(url, extra_headers=headers)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 387, in _request
str(url), method=method, body=data, headers=headers)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 357, in _request_and_retry
url, method=method, body=body, headers=headers)
File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1291, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 132, in _request
return self.retry_on_bad_token(response, content, *args)
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 144, in retry_on_bad_token
self.launchpad.credentials, self.launchpad.credential_store)
File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 545, in __call__
self.make_end_user_authorize_token(credentials, request_token_string)
File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 658, in make_end_user_authorize_token
self.web_root)
File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 233, in exchange_request_token_for_access_token
self.access_token = AccessToken.from_string(content)
File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 251, in from_string
key = params['oauth_token']
KeyError: 'oauth_token'
The problem is that params has b'oauth_token', not 'oauth_token',
which matters on python3
To manage notifications about this bug go to:
https://bugs.launchpad.net/launchpadlib/+bug/1471927/+subscriptions
More information about the foundations-bugs
mailing list