Description: Fix LP: #1471894 This patch fixes a backtrace that happens when the non-anonymous login API is used and the user doesn't have a pre-cached credentials. Author: Zygmunt Krynicki Origin: other Bug-Ubuntu: https://bugs.launchpad.net/launchpadlib/+bug/1471894 Forwarded: https://bugs.launchpad.net/launchpadlib/+bug/1471894 Last-Update: 2015-07-06 --- python-launchpadlib-1.10.3.orig/src/launchpadlib/launchpad.py +++ python-launchpadlib-1.10.3/src/launchpadlib/launchpad.py @@ -122,9 +122,9 @@ class LaunchpadOAuthAwareHttp(RestfulHtt def _bad_oauth_token(self, response, content): """Helper method to detect an error caused by a bad OAuth token.""" return (response.status == 401 and - (content.startswith("Expired token") - or content.startswith("Invalid token") - or content.startswith("Unknown access token"))) + (content.startswith(b"Expired token") + or content.startswith(b"Invalid token") + or content.startswith(b"Unknown access token"))) def _request(self, *args): response, content = super( --- python-launchpadlib-1.10.3.orig/src/launchpadlib/tests/test_http.py +++ python-launchpadlib-1.10.3/src/launchpadlib/tests/test_http.py @@ -39,7 +39,7 @@ from launchpadlib.testing.helpers import # The simplest WADL that looks like a representation of the service root. -SIMPLE_WADL = ''' +SIMPLE_WADL = b''' @@ -58,7 +58,7 @@ SIMPLE_WADL = ''' ''' # The simplest JSON that looks like a representation of the service root. -SIMPLE_JSON = dumps({}) +SIMPLE_JSON = b'{}' class Response: @@ -148,7 +148,7 @@ class TestAbilityToParseData(SimulatedRe """Show that bad WADL causes an exception.""" self.assertRaises( SyntaxError, self.launchpad_with_responses, - Response(200, "This is not WADL."), + Response(200, b"This is not WADL."), Response(200, SIMPLE_JSON)) def test_bad_json(self): @@ -156,7 +156,7 @@ class TestAbilityToParseData(SimulatedRe self.assertRaises( JSONDecodeError, self.launchpad_with_responses, Response(200, SIMPLE_WADL), - Response(200, "This is not JSON.")) + Response(200, b"This is not JSON.")) class TestTokenFailureDuringRequest(SimulatedResponsesTestCase): @@ -182,7 +182,7 @@ class TestTokenFailureDuringRequest(Simu def test_bad_token(self): """If our token is bad, we get another one.""" SimulatedResponsesLaunchpad.responses = [ - Response(401, "Invalid token."), + Response(401, b"Invalid token."), Response(200, SIMPLE_WADL), Response(200, SIMPLE_JSON)] @@ -195,7 +195,7 @@ class TestTokenFailureDuringRequest(Simu """If our token is expired, we get another one.""" SimulatedResponsesLaunchpad.responses = [ - Response(401, "Expired token."), + Response(401, b"Expired token."), Response(200, SIMPLE_WADL), Response(200, SIMPLE_JSON)] @@ -208,7 +208,7 @@ class TestTokenFailureDuringRequest(Simu """If our token is unknown, we get another one.""" SimulatedResponsesLaunchpad.responses = [ - Response(401, "Unknown access token."), + Response(401, b"Unknown access token."), Response(200, SIMPLE_WADL), Response(200, SIMPLE_JSON)] @@ -221,7 +221,7 @@ class TestTokenFailureDuringRequest(Simu """We get another token no matter when the error happens.""" SimulatedResponsesLaunchpad.responses = [ Response(200, SIMPLE_WADL), - Response(401, "Expired token."), + Response(401, b"Expired token."), Response(200, SIMPLE_JSON)] self.assertEqual(self.engine.access_tokens_obtained, 0) @@ -232,10 +232,10 @@ class TestTokenFailureDuringRequest(Simu def test_many_errors(self): """We'll keep getting new tokens as long as tokens are the problem.""" SimulatedResponsesLaunchpad.responses = [ - Response(401, "Invalid token."), + Response(401, b"Invalid token."), Response(200, SIMPLE_WADL), - Response(401, "Expired token."), - Response(401, "Invalid token."), + Response(401, b"Expired token."), + Response(401, b"Invalid token."), Response(200, SIMPLE_JSON)] self.assertEqual(self.engine.access_tokens_obtained, 0) launchpad = SimulatedResponsesLaunchpad.login_with( @@ -246,7 +246,7 @@ class TestTokenFailureDuringRequest(Simu """If the token is not at fault, a 401 error raises an exception.""" SimulatedResponsesLaunchpad.responses = [ - Response(401, "Some other error.")] + Response(401, b"Some other error.")] self.assertRaises( Unauthorized, SimulatedResponsesLaunchpad.login_with,