google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

GMB categories list API throwing KeyError exception

Open ioliveros opened this issue 6 years ago • 3 comments

Hey Guys,

I'm trying to get category list from my gmb account using api-client, I had success using other endpoints such as accounts, accounts.list but when I tried category.list I'm getting a KeyError:'BatchGetBusinessCategoriesResponse' error which is wierd because I'm accessing ListBusinessCategoriesResponse not the latter. I already checked possible revoked tokens or expired, but to no avail nothing worked. My initial assumption is that something is happening within the discovery build is not able to load up all the schema for mybusiness service.

Environment details

  • OS: ubuntu 18.04
  • Python version: 3.6
  • pip version: 20.0.2
  • google-api-python-client==1.8.0
  • google-auth ==1.14.0
  • google-auth-oauthlib == 0.4.1

Steps to reproduce

import httplib2
from oauth2client import client
from apiclient import discovery

ACCESS_TOKEN = <ACCESS_TOKEN>
CLIENT_ID = <CLIENT_ID >
CLIENT_SECRET = <CLIENT_SECRET >
REFRESH_TOKEN = <REFRESH_TOKEN >
EXPIRES_IN = <EXPIRES_IN >
GOOGLE_REFRESH_URL = "https://accounts.google.com/o/oauth2/token"

credentials = client.OAuth2Credentials(
    ACCESS_TOKEN, CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, EXPIRES_IN, GOOGLE_REFRESH_URL, user_agent=''
)
http = credentials.authorize(httplib2.Http())
service = discovery.build(
    'mybusiness', 'v4', http=http, discoveryServiceUrl="https://developers.google.com/my-business/samples/mybusiness_google_rest_v4p5.json"
)
service.categories().list().execute()

traceback

self.pretty[name] = _SchemaToStruct(self.schemas[name], KeyError: 'BatchGetBusinessCategoriesResponse'

kinda similar to this issue, but no definite resolution

Can somebody point me to the right direction? I'm getting kinda frustrated here, since the traceback doesn't really give me much as to suspect that something is wrong with the discovery build or schema, which is beyond me.

Any insights would be much appreciated!

Thank you, Ian

ioliveros avatar Apr 15 '20 04:04 ioliveros

It looks like the discovery doc is invalid. The error is being raised during discovery.build https://github.com/googleapis/google-api-python-client/blob/66bb32cc70353296dbf1876ae8c22baf6562cfb9/googleapiclient/schema.py#L108.

This discovery doc references BatchGetBusinessCategoriesResponse but doesn't provide a schema for it.

If you search through the doc there is only one instance of BatchGetBusinessCategoriesResponse:

          "response": {
            "$ref": "BatchGetBusinessCategoriesResponse"
          },

In contrast other messages have schema definitions and references.

    "ListAttributeMetadataResponse": {
      "id": "ListAttributeMetadataResponse",
      "description": "Response message for Locations.ListAttributeMetadata.",
      "type": "object",
      "properties": {
        "attributes": {
          "description": "A collection of attribute metadata for the available attributes.",
          "type": "array",
          "items": {
            "$ref": "AttributeMetadata"
          }
        },
        "nextPageToken": {
          "description": "If the number of attributes exceeded the requested page size, this field\nwill be populated with a token to fetch the next page of attributes on a\nsubsequent call to `attributes.list`. If there are no more attributes, this\nfield will not be present in the response.",
          "type": "string"
        }
      }
    },
          "response": {
            "$ref": "ListAttributeMetadataResponse"
          },

I'm reaching out to the Backend team internally to ask them about their discovery doc. If you have a support contract, I'd also suggest filing an issue to expedite the process.

busunkim96 avatar Apr 15 '20 16:04 busunkim96

Quick update: the backend team said they recently pushed a change which they suspect is the root cause. They're working on getting it resolved now.

busunkim96 avatar Apr 15 '20 20:04 busunkim96

A new discovery doc has been published with the fix.

busunkim96 avatar Apr 15 '20 21:04 busunkim96