Skip to content

Commit

Permalink
Fix issues with GceAssertionCredentials in Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesccychen committed Feb 2, 2019
1 parent 5cc8d57 commit ebcc7e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apitools/base/py/credentials_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _ScopesFromMetadataServer(self, scopes):
def GetServiceAccount(self, account):
relative_url = 'instance/service-accounts'
response = _GceMetadataRequest(relative_url)
response_lines = [line.rstrip('/\n\r')
response_lines = [line.rstrip(b'/\n\r').decode('utf-8')
for line in response.readlines()]
return account in response_lines

Expand Down Expand Up @@ -395,7 +395,7 @@ def _do_refresh_request(self, unused_http_request):
raise
content = response.read()
try:
credential_info = json.loads(content)
credential_info = json.loads(content.decode('utf-8'))
except ValueError:
raise exceptions.CredentialsError(
'Could not parse response as JSON: %s' % content)
Expand Down
5 changes: 3 additions & 2 deletions apitools/base/py/credentials_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def _RunGceAssertionCredentials(
self, service_account_name=None, scopes=None, cache_filename=None):
kwargs = {}
if service_account_name is not None:
kwargs['service_account_name'] = service_account_name
kwargs['service_account_name'] = (
service_account_name.encode('utf-8'))
if cache_filename is not None:
kwargs['cache_filename'] = cache_filename
service_account_name = service_account_name or 'default'
service_account_name = service_account_name or b'default'
credentials = credentials_lib.GceAssertionCredentials(
scopes, **kwargs)
self.assertIsNone(credentials._refresh(None))
Expand Down

0 comments on commit ebcc7e7

Please sign in to comment.