googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.55k stars 2.37k forks source link

pollen API not available #2415

Closed MicZet closed 1 week ago

MicZet commented 3 weeks ago

Thanks for stopping by to let us know something could be better!

Environment details

Steps to reproduce

  1. execute example script (pasted below)

Code example

from googleapiclient.discovery import build

api_service_name = "pollen"
api_version = "v1"
endpoint = build(api_service_name, api_version, developerKey=api_key)
print(endpoint) # here already error, rest not even executed

lat = {
    "latitude": 11.7898095,
    "longitude": 13.0238652,
}
metadata = {
    "location": lat,
    "days": 5,
}
request = endpoint.forecast().lookup(
    body=metadata
)

response = request.execute()

Stack trace

    endpoint = build(api_service_name, api_version, developerKey=api_key)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/m/.venvs/pythonenv/lib/python3.11/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/m/.venvs/pythonenv/lib/python3.11/site-packages/googleapiclient/discovery.py", line 304, in build
    content = _retrieve_discovery_doc(
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/m/.venvs/pythonenv/lib/python3.11/site-packages/googleapiclient/discovery.py", line 421, in _retrieve_discovery_doc
    raise UnknownApiNameOrVersion(
googleapiclient.errors.UnknownApiNameOrVersion: name: pollen  version: v1

Looking at https://developers.google.com/maps/documentation/pollen/reference/rest and comparing to other endpoints - attached script should work but unfortunately it isnt (error attached) looks like library doesn't support it?!

ohmayr commented 2 weeks ago

Hi @MicZet, Thanks for reporting this issue.

The request fails because it's unable to find the pollen API in the cached directory: discovery cache.

As a workaround, you should be able to fetch the discovery document directly by setting static_discovery=False in the following way:

 service = build('pollen', version="v1", static_discovery=False)

This issue should be fixed once the artifacts are updated by the following PR https://github.com/googleapis/google-api-python-client/pull/2419 and explicitly setting static_discovery=False won't be required once the discovery document for the API is available in the cached directory.

MicZet commented 1 week ago

Thanks a lot @ohmayr this steps succeed and return proper value

and btw in newest version i see endpoint is available.