question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnknownApiNameOrVersion exception with commentanalyzer

See original GitHub issue

Environment details

  • OS type and version: latest Manjaro Linux
  • Python version: 3.9.1
  • pip version: 20.3.1
  • google-api-python-client version: 2.0.2

Steps to reproduce

Just got my API access from them, made a project, added an API key, and their sample code wouldn’t work.

  1. Run code - it’s from the offical website https://support.perspectiveapi.com/s/docs-sample-requests

Code example

from googleapiclient import discovery
import json

API_KEY = ""

# Generates API client object dynamically based on service name and version.
service = discovery.build("commentanalyzer", "v1alpha1", developerKey=API_KEY)

analyze_request = {
    "comment": {"text": "friendly greetings from python"},
    "requestedAttributes": {"TOXICITY": {}},
}

response = service.comments().analyze(body=analyze_request).execute()


print(json.dumps(response, indent=2))

Stack trace

Traceback (most recent call last):
  File "/home/enkeyz/stuff/discord/detox.ai/bot/test.py", line 7, in <module>
    service = discovery.build("commentanalyzer", "v1alpha1", developerKey=API_KEY)
  File "/home/enkeyz/.local/share/virtualenvs/detox.ai-WfgfN2Jd/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/enkeyz/.local/share/virtualenvs/detox.ai-WfgfN2Jd/lib/python3.9/site-packages/googleapiclient/discovery.py", line 273, in build
    content = _retrieve_discovery_doc(
  File "/home/enkeyz/.local/share/virtualenvs/detox.ai-WfgfN2Jd/lib/python3.9/site-packages/googleapiclient/discovery.py", line 387, in _retrieve_discovery_doc
    raise UnknownApiNameOrVersion("name: %s  version: %s" % (serviceName, version))
googleapiclient.errors.UnknownApiNameOrVersion: name: commentanalyzer  version: v1alpha1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
busunkim96commented, Mar 8, 2021

Hi @enkeyz,

From looking at the NodeJS sample linked on the documentation page, it looks like ‘https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1’ is the discovery URL.

from googleapiclient import discovery

client = discovery.build(
    "commentanalyzer",
    "v1alpha1",
    discoveryServiceUrl="https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1",
    static_discovery=False,
)

I’ll reach out to the comment analyzer team to see if they can get their API listed in the directory.

1reaction
busunkim96commented, Mar 8, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

UnknownApiNameOrVersion exception when building the ...
Attempt to build the cloudcommerceprocurement api. Code example. def get_procurement_api(): return build('cloudcommerceprocurement', 'v1', ...
Read more >
googleapiclient.errors.UnknownApiNameOrVersion: name ...
And when i pass static_discovery=False it building successfully but gets me forbidden error when i try this https://www.googleapis.com/youtube/ ...
Read more >
googleapiclient.errors.UnknownApiNameOrVersion
No API with that name and version exists. Instance Methods, [hide private]. Inherited from exceptions.Exception ...
Read more >
Exceptions — google-api-core documentation
This module provides base classes for all errors raised by libraries based on google.api_core , including both HTTP and gRPC clients. exception google.api_core....
Read more >
Issues-googleapis/google-api-python-client - PythonTechWorld
UnknownApiNameOrVersion exception with commentanalyzer. 888. Environment details OS type and version: latest Manjaro Linux Python version: 3.9.1 pip ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found