google-api-python-client: v3 discovery json document does not contain rootURL.

Environment details

  • Python version: Python 3.7.3
  • pip version: pip 18.1
  • google-api-python-client version: 1.12.3

Steps to reproduce

  1. Attempt to build for analytics v3 build("analytics", "v3", ...)
  2. Receive key error in below stack trace where service does not contain rootURL.

a. traced code back to REST call to: “https://www.googleapis.com/discovery/v1/apis/analytics/v3/rest” b. return from GET to that endpoint does not contain a rootURL entry. c. cooreponding google bugtracker ticket @ https://issuetracker.google.com/u/1/issues/170661562 opened by another person.

Code example

build("analytics", "v3", credentials = get_ga_creds(creds), cache_discovery = False)

Stack trace

~/cddl/sources/google_analytics/extract.py in connect_ga_v3(creds)
     48 
     49 def connect_ga_v3(creds):
---> 50     return build("analytics", "v3", credentials = get_ga_creds(creds), cache_discovery = False)
     51 
     52 

/usr/local/lib/python3.7/dist-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

/usr/local/lib/python3.7/dist-packages/googleapiclient/discovery.py in build(serviceName, version, http, discoveryServiceUrl, developerKey, model, requestBuilder, credentials, cache_discovery, cache, client_options, adc_cert_path, adc_key_path, num_retries)
    286                 client_options=client_options,
    287                 adc_cert_path=adc_cert_path,
--> 288                 adc_key_path=adc_key_path,
    289             )
    290             break  # exit if a service was created

/usr/local/lib/python3.7/dist-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

/usr/local/lib/python3.7/dist-packages/googleapiclient/discovery.py in build_from_document(service, base, future, http, developerKey, model, requestBuilder, credentials, client_options, adc_cert_path, adc_key_path)
    492 
    493     # If an API Endpoint is provided on client options, use that as the base URL
--> 494     base = urljoin(service["rootUrl"], service["servicePath"])
    495     if client_options.api_endpoint:
    496         base = client_options.api_endpoint

KeyError: 'rootUrl'

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Looks like it’s fixed now. https://www.googleapis.com/discovery/v1/apis/analytics/v3/rest has ‘rootUrl’ again.

This happened to me also this afternoon, after 5PM EST. It seems the default service discovery document returned by the discovery endpoint of the client library no longer returns the rootUrl property in the document.

I managed to work around it by copying the response of https://www.googleapis.com/discovery/v1/apis/analytics/v3/rest in a JSON file hosted on S3, in that file I added the rootUrl property that the client library expects like this:

"rootUrl" : "https://www.googleapis.com/"

I then overrode the discoveryServiceUrl endpoint on the build method to point to a different service discovery document hosted by me in a custom endpoint:

service = build('analytics', 'v3', http=http, discoveryServiceUrl="https://example.com/service-discovery-v1.json")

Of course, this is a temporary solution for me since I need to keep my software running, but I ideally Google will fix this soon or provide more guidance.

I hope this helps someone.

I believe it is possible to get the base URL from the attribute baseUrl instead of composing it from rootUrl. So, instead of

base = urljoin(service["rootUrl"], service["servicePath"])

you could have

base = service["baseUrl"]

Looks like it’s fixed now. https://www.googleapis.com/discovery/v1/apis/analytics/v3/rest has ‘rootUrl’ again.

yeah, it’s back to normal