Skip to content

Commit

Permalink
Merge pull request #2 from maxwell-k/python3
Browse files Browse the repository at this point in the history
Merging PR.  Decode url content if on Python 3
  • Loading branch information
pferate committed Jan 28, 2015
2 parents ce5c5cf + 08dfb1f commit 15babeb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
]


import six
from six import StringIO
from six.moves.urllib.parse import urlencode, urlparse, urljoin,\
urlunparse, parse_qs, parse_qsl
urlunparse, parse_qsl

# Standard library imports
import copy
Expand Down Expand Up @@ -64,8 +65,6 @@
from oauth2client.util import _add_query_parameter
from oauth2client.util import positional

import sys

# The client library requires a version of httplib2 that supports RETRIES.
httplib2.RETRIES = 1

Expand Down Expand Up @@ -216,6 +215,8 @@ def build(serviceName,
logger.info('URL being requested: GET %s' % requested_url)

resp, content = http.request(requested_url)
if six.PY3 and isinstance(content, bytes):
content = content.decode('utf-8')

if resp.status == 404:
raise UnknownApiNameOrVersion("name: %s version: %s" % (serviceName,
Expand All @@ -224,8 +225,8 @@ def build(serviceName,
raise HttpError(resp, content, uri=requested_url)

try:
service = json.loads(content)
except ValueError as e:
json.loads(content)
except ValueError:
logger.error('Failed to parse as JSON: ' + content)
raise InvalidJsonError()

Expand Down

0 comments on commit 15babeb

Please sign in to comment.