Skip to content

discovery.build_from_document fails when running with Python3 #720

Closed
@mbonvini

Description

@mbonvini

The discovery.build_from_document function assumes that service is of type str, however when running in Python3 instead of str it can be of type bytes.

Because of this wrong assumption, the function fails on line 337 where the bytes string is compared to an actual text string.

The google-api-python-client version where i've seen this problem is 1.7.7

Solution

Add a check, if service is a bytes string convert it using UTF-8 format

  if isinstance(service, six.string_types):
      service = json.loads(service)
+ elif isinstance(service, six.binary_type):
+  service = json.loads(service.decode('utf8'))

This fixes my problem (observed when using this library in Google3)

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions