[Bug 1471894] Re: _bad_oauth_token crashes on python3 (str vs bytes)

Tiago Stürmer Daitx 1471894 at bugs.launchpad.net
Mon Feb 6 20:39:49 UTC 2017


Yes, I can confirm that the package in -proposed fixes that.

Now:
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from launchpadlib.launchpad import Launchpad
>>> def no_credential():
...     print("Can't proceed without Launchpad credential.")
...     sys.exit()
... 
>>> launchpad = Launchpad.login_with('Test', 'production', credential_save_failed=no_credential, version='devel')
>>> me = launchpad.me
>>> me.getPPAByName(name="openjdk")
The authorization page:
 (https://launchpad.net/+authorize-token?oauth_token=NotMyRealTokenOfCourse&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...
Created new window in existing browser session.
<archive at https://api.launchpad.net/devel/~tdaitx/+archive/ubuntu/openjdk>

Before:
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from launchpadlib.launchpad import Launchpad
>>> def no_credential():
...     print("Can't proceed without Launchpad credential.")
...     sys.exit()
... 
>>> launchpad = Launchpad.login_with('Test', 'production', credential_save_failed=no_credential, version='devel')
>>> me = launchpad.me
>>> me.getPPAByName(name="openjdk")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 609, in __call__
    extra_headers=extra_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 1312, 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 139, in retry_on_bad_token
    if (self._bad_oauth_token(response, content)
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 125, in _bad_oauth_token
    (content.startswith(b"Expired token")
TypeError: startswith first arg must be bytes or a tuple of bytes, not str


** 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/1471894

Title:
  _bad_oauth_token crashes on python3 (str vs bytes)

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]

  Hi

  Running something as simple as

  >>> from launchpadlib.launchpad import Launchpad
  >>> launchpad = Launchpad.login_with("app", "production")

  Results in a traceback such as this one:

  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 139, in retry_on_bad_token
      if (self._bad_oauth_token(response, content)
    File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 125, in _bad_oauth_token
      (content.startswith("Expired token")
  TypeError: startswith first arg must be bytes or a tuple of bytes, not str

  This doesn't happen on python2. I will follow up with a patch shortly.

To manage notifications about this bug go to:
https://bugs.launchpad.net/launchpadlib/+bug/1471894/+subscriptions



More information about the foundations-bugs mailing list