GithubHelp home page GithubHelp logo

googleapis / python-language Goto Github PK

View Code? Open in Web Editor NEW
67.0 42.0 44.0 1.78 MB

This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-language

License: Apache License 2.0

python-language's Introduction

NOTE:This github repository is archived. The repository contents and history have moved to google-cloud-python.

Python Client for Natural Language API

stable pypi versions

Natural Language API: provides natural language understanding technologies to developers, including sentiment analysis, entity analysis, entity sentiment analysis, content classification, and syntax analysis. This API is part of the larger Cloud Machine Learning API family.

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Natural Language API.
  4. Setup Authentication.

Installation

Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.

With virtualenv, it's possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.

Code samples and snippets

Code samples and snippets live in the samples/ folder.

Supported Python Versions

Our client libraries are compatible with all current active and maintenance versions of Python.

Python >= 3.7

Unsupported Python Versions

Python <= 3.6

If you are using an end-of-life version of Python, we recommend that you update as soon as possible to an actively supported version.

Mac/Linux
pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-language
Windows
pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-cloud-language

Next Steps

python-language's People

Contributors

alixhami avatar andrewferlitsch avatar beccasaurus avatar busunkim96 avatar crwilcox avatar dandhlee avatar daspecster avatar dhermes avatar dizcology avatar dpebot avatar engelke avatar gcf-owl-bot[bot] avatar gguuss avatar hkdevandla avatar jerjou avatar jmdobry avatar jsimonweb avatar leahecole avatar lukesneeringer avatar m-strzelczyk avatar nnegrey avatar parthea avatar puneithk avatar release-please[bot] avatar renovate-bot avatar sirtorry avatar tseaver avatar tswast avatar wizeng23 avatar yoshi-automation avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-language's Issues

TypeError: analyze_entities() got an unexpected keyword argument 'request'

I'm trying this task https://github.com/googleapis/python-language/blob/master/samples/v1/language_entities_text.py
but script returns exception: 'google.cloud.language_v1' has no attribute 'Document'.
I fixed it by
language_v1 => 'from google.cloud.language import enums', 'from google.cloud.language import types'

But now I have next exception:
TypeError: analyze_entities() got an unexpected keyword argument 'request'.

Where I can find actual/updated example of entity extraction code using Natural Language API?

Module 'google.cloud.language_v1' has no attribute 'ClassificationModelOptions'

Context: Error while making the API call to get categories from V2 Model. Script is running fine for old code with default version.

Problem: I have a script that uses the google.cloud.language_v1 module to perform text classification on a set of records every day. It was working fine until I made modifications to use the V2Model content categories.

I changed the content_categories_version value to explicitly specify the version for the model. I used the code from language_classify_text.py sample by @wizeng23 in the github repo. However, on running the script I receive the below error:

module 'google.cloud.language_v1' has no attribute 'ClassificationModelOptions'

Environment details

  • OS type and version: macOS Monterey Version 12.6
  • Python version: 3.7.13
  • pip version: 22.0.4
  • google-cloud-language version: 2.5.1

Steps to reproduce

  1. Initialize document and content_categories_version as below.
  2. Run the script with a text string

Code example

## Providing the code I'm using for testing the API call:

import os
from google.cloud import language_v1

## Set Google API Key
os.environ.get("GOOGLE_APPLICATION_CREDENTAILS")

client = language_v1.LanguageServiceClient()

def categorize(txt):
    """
    Takes a string as an argument and returns the category with highest confidence received from the Google NLP API.
    """
    result = {}

    document = language_v1.Document(content = txt, type_=language_v1.types.Document.Type.PLAIN_TEXT)
    content_categories_version = (language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2)
    request_json = {
        "document": document,
        "classification_model_options": {
            "v2_model": {
                "content_categories_version": content_categories_version
                }
            }
        }

    response = client.classify_text(request=request_json)
    print(response)

    for category in response.categories:
        result[category.name] = category.confidence
    
    print(result)

    best_response = max(result, key = result.get)

    lst = best_response.split(sep = '/')
    out_category = lst[-1]
          
    return out_category

txt = 'Dungeons and Dragons'

categorize(txt)

Stack trace

Traceback (most recent call last):
  File "nlp_api_test.py", line 43, in <module>
    categorize(txt)
  File "nlp_api_test.py", line 16, in categorize
    content_categories_version = (language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2)
AttributeError: module 'google.cloud.language_v1' has no attribute 'ClassificationModelOptions'

Please let me know if I'm doing anything incorrectly.

Thanks!

samples.snippets.classify_text.classify_text_tutorial_test: test_query_category failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
capsys = <_pytest.capture.CaptureFixture object at 0x7f3110447d00>
index_file = local('/tmp/pytest-of-root/pytest-0/tmp0/index.json')
def test_query_category(capsys, index_file):
    temp_out = index_file.strpath

    classify_text_tutorial.query_category(temp_out, QUERY_CATEGORY)
    out, err = capsys.readouterr()
  assert "Filename: cloud_computing.txt" in out

E AssertionError: assert 'Filename: cloud_computing.txt' in '====================\nQuery: /Computers & Electronics/Software\n\n\nMost similar 3 indexed texts:\n\tFilename: eclips...t\n\tSimilarity: 0.0\n\n\n\tFilename: gcp.txt\n\tSimilarity: 0.0\n\n\n\tFilename: eclipse.txt\n\tSimilarity: 0.0\n\n\n'

classify_text_tutorial_test.py:73: AssertionError

Synthesis failed for python-language

Hello! Autosynth couldn't regenerate python-language. ๐Ÿ’”

Here's the output from running synth.py:

G] > Ensuring dependencies.
2021-01-28 05:43:41,352 synthtool [DEBUG] > Using precloned repo /home/kbuilder/.cache/synthtool/synthtool
2021-01-28 05:43:41,356 synthtool [DEBUG] > Cloning googleapis.
2021-01-28 05:43:41,356 synthtool [DEBUG] > Using precloned repo /home/kbuilder/.cache/synthtool/googleapis
2021-01-28 05:43:41,360 synthtool [DEBUG] > Which version of bazel will I run?
bazel 3.0.0
2021-01-28 05:43:41,364 synthtool [DEBUG] > Generating code for: //google/cloud/language/v1beta2:language-v1beta2-py.
2021-01-28 05:43:42,473 synthtool [ERROR] > Failed executing bazel --max_idle_secs=240 build //google/cloud/language/v1beta2:language-v1beta2-py:

Loading: 
Loading: 0 packages loaded
DEBUG: /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/rules_python/python/pip.bzl:61:5: DEPRECATED: the pip_repositories rule has been replaced with pip_install, please see rules_python 0.1 release notes
Analyzing: target //google/cloud/language/v1beta2:language-v1beta2-py (1 packages loaded, 0 targets configured)
INFO: Analyzed target //google/cloud/language/v1beta2:language-v1beta2-py (1 packages loaded, 5 targets configured).
INFO: Found 1 target...
[0 / 4] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ERROR: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1beta2/BUILD.bazel:154:1: //google/cloud/language/v1beta2:language_py_gapic: `bazel-out/host/bin/external/com_google_protobuf/protoc --experimental_allow_proto3_optional --plugin=protoc-gen-python_gapic=bazel-out/host/bin/external/gapic_generator_python/gapic_plugin --python_gapic_out=retry-config=google/cloud/language/v1beta2/language_grpc_service_config.json:bazel-out/k8-fastbuild/bin/google/cloud/language/v1beta2/language_py_gapic.srcjar.zip -Igoogle/cloud/language/v1beta2/language_service.proto=google/cloud/language/v1beta2/language_service.proto -Igoogle/api/annotations.proto=google/api/annotations.proto -Igoogle/api/http.proto=google/api/http.proto -Igoogle/protobuf/descriptor.proto=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_imports/descriptor_proto/google/protobuf/descriptor.proto -Igoogle/api/client.proto=google/api/client.proto -Igoogle/api/field_behavior.proto=google/api/field_behavior.proto -Igoogle/protobuf/timestamp.proto=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_imports/timestamp_proto/google/protobuf/timestamp.proto google/cloud/language/v1beta2/language_service.proto` failed (Exit 1) protoc failed: error executing command bazel-out/host/bin/external/com_google_protobuf/protoc --experimental_allow_proto3_optional '--plugin=protoc-gen-python_gapic=bazel-out/host/bin/external/gapic_generator_python/gapic_plugin' ... (remaining 9 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
google/cloud/language/v1beta2/language_service.proto:23:1: warning: Import google/protobuf/timestamp.proto is unused.
Traceback (most recent call last):
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/cli/generate_with_pandoc.py", line 3, in <module>
    from gapic.cli import generate
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/cli/generate.py", line 23, in <module>
    from gapic import generator
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/generator/__init__.py", line 21, in <module>
    from .generator import Generator
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/generator/generator.py", line 24, in <module>
    from gapic.samplegen import manifest, samplegen
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/samplegen/__init__.py", line 15, in <module>
    from gapic.samplegen import samplegen
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/samplegen/samplegen.py", line 27, in <module>
    from gapic.schema import wrappers
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/schema/__init__.py", line 23, in <module>
    from gapic.schema.api import API
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/21/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/schema/api.py", line 29, in <module>
    from google.api_core import exceptions  # type: ignore
ModuleNotFoundError: No module named 'google.api_core'
--python_gapic_out: protoc-gen-python_gapic: Plugin failed with status code 1.
Target //google/cloud/language/v1beta2:language-v1beta2-py failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.095s, Critical Path: 0.83s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 102, in <module>
    main()
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 94, in main
    spec.loader.exec_module(synth_module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/kbuilder/.cache/synthtool/python-language/synth.py", line 34, in <module>
    include_protos=True,
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 52, in py_library
    return self._generate_code(service, version, "python", **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 197, in _generate_code
    shell.run(bazel_run_args)
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 39, in run
    raise exc
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 33, in run
    encoding="utf-8",
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['bazel', '--max_idle_secs=240', 'build', '//google/cloud/language/v1beta2:language-v1beta2-py']' returned non-zero exit status 1.
2021-01-28 05:43:42,540 autosynth [ERROR] > Synthesis failed
2021-01-28 05:43:42,540 autosynth [DEBUG] > Running: git reset --hard HEAD
HEAD is now at 7d910d5 chore(deps): update dependency google-auth to v1.24.0 (#65)
2021-01-28 05:43:42,546 autosynth [DEBUG] > Running: git checkout autosynth
Switched to branch 'autosynth'
2021-01-28 05:43:42,551 autosynth [DEBUG] > Running: git clean -fdx
Removing __pycache__/
Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 354, in <module>
    main()
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 189, in main
    return _inner_main(temp_dir)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 334, in _inner_main
    commit_count = synthesize_loop(x, multiple_prs, change_pusher, synthesizer)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 65, in synthesize_loop
    has_changes = toolbox.synthesize_version_in_new_branch(synthesizer, youngest)
  File "/tmpfs/src/github/synthtool/autosynth/synth_toolbox.py", line 259, in synthesize_version_in_new_branch
    synthesizer.synthesize(synth_log_path, self.environ)
  File "/tmpfs/src/github/synthtool/autosynth/synthesizer.py", line 120, in synthesize
    synth_proc.check_returncode()  # Raise an exception.
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 389, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']' returned non-zero exit status 1.

Google internal developers can see the full log here.

Language API Unicode Error

I am using the sample code found here https://cloud.google.com/natural-language/docs/samples/language-syntax-gcs#language_syntax_gcs-python.

I've setup the response like the following:

client = language_v1.LanguageServiceClient()

gcs_content_uri = 'gs://my-url-here.txt'

type_ = language_v1.Document.Type.PLAIN_TEXT

language = "fr"

document = {"gcs_content_uri": gcs_content_uri, "type_": type_, "language": language}

encoding_type = language_v1.EncodingType.UTF8

response = client.analyze_syntax(request = {'document': document, 'encoding_type': encoding_type})

However, the results I get back have hex representations of unicode characters (I think) in them.

Sample response text looks like this, with accented, and potentially other unicode characters being returned in the following manner:

content: "Au coucher du soleil, le taxi nous a d\303\251pos\303\251s devant la\nplage de Santa Monica."
begin_offset: 449122

content: "Elle \303\251tait exactement comme les\nplages de Los Angeles qu\342\200\231on voit dans les \357\254\201lms, sauf qu\342\200\231elle\nsentait mauvais."
begin_offset: 449202

This looks to be a bug in the charset/encoding of the responses that are returned.

samples.snippets.cloud-client.v1.quickstart_test: test_quickstart failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
args = (document {
  type_: PLAIN_TEXT
  content: "Hello, world!"
}
,)
kwargs = {'metadata': [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]}
@six.wraps(callable_)
def error_remapped_callable(*args, **kwargs):
    try:
      return callable_(*args, **kwargs)

.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:67:


self = <grpc._channel.UnaryUnaryMultiCallable object at 0x7f755c52e1f0>
request = document {
type
: PLAIN_TEXT
content: "Hello, world!"
}

timeout = None
metadata = [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]
credentials = None, wait_for_ready = None, compression = None

def __call__(self,
             request,
             timeout=None,
             metadata=None,
             credentials=None,
             wait_for_ready=None,
             compression=None):
    state, call, = self._blocking(request, timeout, metadata, credentials,
                                  wait_for_ready, compression)
  return _end_unary_response_blocking(state, call, False, None)

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:946:


state = <grpc._channel._RPCState object at 0x7f755c54cf70>
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f755c546700>
with_call = False, deadline = None

def _end_unary_response_blocking(state, call, with_call, deadline):
    if state.code is grpc.StatusCode.OK:
        if with_call:
            rendezvous = _MultiThreadedRendezvous(state, call, None, deadline)
            return state.response, rendezvous
        else:
            return state.response
    else:
      raise _InactiveRpcError(state)

E grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
E status = StatusCode.UNAUTHENTICATED
E details = "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
E debug_error_string = "{"created":"@1626174391.848535256","description":"Error received from peer ipv4:74.125.20.95:443","file":"src/core/lib/surface/call.cc","file_line":1066,"grpc_message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
E >

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:849: _InactiveRpcError

The above exception was the direct cause of the following exception:

capsys = <_pytest.capture.CaptureFixture object at 0x7f755e786bb0>

def test_quickstart(capsys):
  quickstart.run_quickstart()

quickstart_test.py:20:


quickstart.py:36: in run_quickstart
sentiment = client.analyze_sentiment(request={'document': document}).document_sentiment
../../../../google/cloud/language_v1/services/language_service/client.py:402: in analyze_sentiment
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py:145: in call
return wrapped_func(*args, **kwargs)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:285: in retry_wrapped_func
return retry_target(
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:188: in retry_target
return target()
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:69: in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)


value = None
from_value = <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request had invalid a...entication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"

???
E google.api_core.exceptions.Unauthenticated: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

:3: Unauthenticated

Error: gRPC error on request if code executed by Gunicorn

Hello,

Getting an error when using google.oauth2.service_account.LanguageServiceClient in Flask application executed by Gunicorn

Environment details

  • Docker image: python:3.10.4
  • Python version: 3.10
  • pip version: 22.0.4
  • google-cloud-language version: 2.4.1

Steps to reproduce

  1. Run code using Gunicorn: https://github.com/rizzzhik/belinsky/blob/feature/gcloud_nlp/docker-compose.yaml

Code example

  1. Repository: https://github.com/rizzzhik/belinsky/tree/feature/gcloud_nlp
  2. Actual usage: https://github.com/riZZZhik/belinsky/blob/feature/gcloud_nlp/app/belinsky/routes/text_analyzer/text_analyzer.py

Stack trace

Without gRPC environments:

Code freezes on self.client.classify_text(document=document)

With gRPC environments:

# Due to: https://github.com/grpc/grpc/blob/master/doc/fork_support.md
export GRPC_ENABLE_FORK_SUPPORT=true
export GRPC_POLL_STRATEGY=poll

Trace:

belinsky_app       | Traceback (most recent call last):
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
belinsky_app       |     response = self.full_dispatch_request()
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
belinsky_app       |     rv = self.handle_user_exception(e)
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
belinsky_app       |     rv = self.dispatch_request()
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
belinsky_app       |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
belinsky_app       |   File "<decorator-gen-6>", line 2, in text_analyzer
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/prometheus_client/context_managers.py", line 81, in wrapped
belinsky_app       |     return func(*args, **kwargs)
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/flask_login/utils.py", line 277, in decorated_view
belinsky_app       |     return current_app.ensure_sync(func)(*args, **kwargs)
belinsky_app       |   File "/belinsky/belinsky/routes/text_analyzer/__init__.py", line 45, in text_analyzer
belinsky_app       |     analyzis = getattr(text_analyzer_worker, analyzis_type)(text)
belinsky_app       |   File "/belinsky/belinsky/routes/text_analyzer/text_analyzer.py", line 30, in classify_text
belinsky_app       |     return self.client.classify_text(document=document)
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/google/cloud/language_v1/services/language_service/client.py", line 852, in classify_text
belinsky_app       |     response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
belinsky_app       |     return wrapped_func(*args, **kwargs)
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/google/api_core/retry.py", line 283, in retry_wrapped_func
belinsky_app       |     return retry_target(
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/google/api_core/retry.py", line 190, in retry_target
belinsky_app       |     return target()
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
belinsky_app       |     return callable_(*args, **kwargs)
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/grpc/_channel.py", line 944, in __call__
belinsky_app       |     state, call, = self._blocking(request, timeout, metadata, credentials,
belinsky_app       |   File "/usr/local/lib/python3.10/site-packages/grpc/_channel.py", line 926, in _blocking
belinsky_app       |     call = self._channel.segregated_call(
belinsky_app       |   File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 498, in grpc._cython.cygrpc.Channel.segregated_call
belinsky_app       |   File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 353, in grpc._cython.cygrpc._segregated_call
belinsky_app       |   File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 357, in grpc._cython.cygrpc._segregated_call
belinsky_app       | ValueError: Cannot invoke RPC on closed channel!

samples.snippets.api.analyze_test: test_analyze_syntax_utf16 failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
def test_analyze_syntax_utf16():
        """Demonstrate the interpretation of the offsets when encoding=utf16.
    UTF16 is a variable-length encoding, where each character is at least 16
    bits. The returned offsets will be the index of the first 2-byte character
    of the token.
    """
    test_string = u"a \u00e3 \u0201 \U0001f636 b"
    byte_array = test_string.encode("utf16")
    # Remove the byte order marker, which the offsets don't account for
    byte_array = byte_array[2:]
  result = analyze.analyze_syntax(test_string, encoding="UTF16")

analyze_test.py:124:


analyze.py:71: in analyze_syntax
response = request.execute()
.nox/py-3-6/lib/python3.6/site-packages/googleapiclient/_helpers.py:134: in positional_wrapper
return wrapped(*args, **kwargs)
.nox/py-3-6/lib/python3.6/site-packages/googleapiclient/http.py:929: in execute
headers=self.headers,
.nox/py-3-6/lib/python3.6/site-packages/googleapiclient/http.py:191: in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
.nox/py-3-6/lib/python3.6/site-packages/google_auth_httplib2.py:209: in request
self.credentials.before_request(self._request, method, uri, request_headers)
.nox/py-3-6/lib/python3.6/site-packages/google/auth/credentials.py:133: in before_request
self.refresh(request)
.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/service_account.py:408: in refresh
request, self._token_uri, assertion
.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/_client.py:193: in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/_client.py:165: in _token_endpoint_request
_handle_error_response(response_data)


response_data = {'error': 'invalid_grant', 'error_description': 'Invalid JWT Signature.'}

def _handle_error_response(response_data):
    """Translates an error response into an exception.

    Args:
        response_data (Mapping): The decoded response data.

    Raises:
        google.auth.exceptions.RefreshError: The errors contained in response_data.
    """
    try:
        error_details = "{}: {}".format(
            response_data["error"], response_data.get("error_description")
        )
    # If no details could be extracted, use the response data.
    except (KeyError, ValueError):
        error_details = json.dumps(response_data)
  raise exceptions.RefreshError(error_details, response_data)

E google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT Signature.', {'error': 'invalid_grant', 'error_description': 'Invalid JWT Signature.'})

.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/_client.py:60: RefreshError

Synthesis failed for python-language

Hello! Autosynth couldn't regenerate python-language. ๐Ÿ’”

Here's the output from running synth.py:

erator_python/requirements.txt (line 4))
  Using cached https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl
  Saved ./Jinja2-2.11.2-py2.py3-none-any.whl
Collecting MarkupSafe==1.1.1 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 5))
  Using cached https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
  Saved ./MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Collecting protobuf==3.13.0 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 6))
  Using cached https://files.pythonhosted.org/packages/30/79/510974552cebff2ba04038544799450defe75e96ea5f1675dbf72cc8744f/protobuf-3.13.0-cp36-cp36m-manylinux1_x86_64.whl
  Saved ./protobuf-3.13.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting pypandoc==1.5 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 7))
  Using cached https://files.pythonhosted.org/packages/d6/b7/5050dc1769c8a93d3ec7c4bd55be161991c94b8b235f88bf7c764449e708/pypandoc-1.5.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmpfs/tmp/tmp41bf7mq4/setuptools-tmp/setuptools/__init__.py", line 6, in <module>
        import distutils.core
      File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/_distutils_hack/__init__.py", line 82, in create_module
        return importlib.import_module('._distutils', 'setuptools')
      File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ModuleNotFoundError: No module named 'setuptools._distutils'
    
    ----------------------------------------
 (Command "python setup.py egg_info" failed with error code 1 in /tmpfs/tmp/pip-build-23fgxxj0/pypandoc/
)
ERROR: no such package '@gapic_generator_python_pip_deps//': pip_import failed: Collecting click==7.1.2 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl
  Saved ./click-7.1.2-py2.py3-none-any.whl
Collecting google-api-core==1.22.1 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 2))
  Using cached https://files.pythonhosted.org/packages/e0/2d/7c6c75013105e1d2b6eaa1bf18a56995be1dbc673c38885aea31136e9918/google_api_core-1.22.1-py2.py3-none-any.whl
  Saved ./google_api_core-1.22.1-py2.py3-none-any.whl
Collecting googleapis-common-protos==1.52.0 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 3))
  Using cached https://files.pythonhosted.org/packages/03/74/3956721ea1eb4bcf7502a311fdaa60b85bd751de4e57d1943afe9b334141/googleapis_common_protos-1.52.0-py2.py3-none-any.whl
  Saved ./googleapis_common_protos-1.52.0-py2.py3-none-any.whl
Collecting jinja2==2.11.2 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 4))
  Using cached https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl
  Saved ./Jinja2-2.11.2-py2.py3-none-any.whl
Collecting MarkupSafe==1.1.1 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 5))
  Using cached https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
  Saved ./MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Collecting protobuf==3.13.0 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 6))
  Using cached https://files.pythonhosted.org/packages/30/79/510974552cebff2ba04038544799450defe75e96ea5f1675dbf72cc8744f/protobuf-3.13.0-cp36-cp36m-manylinux1_x86_64.whl
  Saved ./protobuf-3.13.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting pypandoc==1.5 (from -r /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/gapic_generator_python/requirements.txt (line 7))
  Using cached https://files.pythonhosted.org/packages/d6/b7/5050dc1769c8a93d3ec7c4bd55be161991c94b8b235f88bf7c764449e708/pypandoc-1.5.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmpfs/tmp/tmp41bf7mq4/setuptools-tmp/setuptools/__init__.py", line 6, in <module>
        import distutils.core
      File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/_distutils_hack/__init__.py", line 82, in create_module
        return importlib.import_module('._distutils', 'setuptools')
      File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ModuleNotFoundError: No module named 'setuptools._distutils'
    
    ----------------------------------------
 (Command "python setup.py egg_info" failed with error code 1 in /tmpfs/tmp/pip-build-23fgxxj0/pypandoc/
)
INFO: Elapsed time: 2.351s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)

Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 102, in <module>
    main()
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 94, in main
    spec.loader.exec_module(synth_module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/kbuilder/.cache/synthtool/python-language/synth.py", line 33, in <module>
    include_protos=True,
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 46, in py_library
    return self._generate_code(service, version, "python", **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 183, in _generate_code
    shell.run(bazel_run_args)
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 39, in run
    raise exc
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 33, in run
    encoding="utf-8",
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['bazel', '--max_idle_secs=240', 'build', '//google/cloud/language/v1beta2:language-v1beta2-py']' returned non-zero exit status 1.
2020-08-31 05:19:53,341 autosynth [ERROR] > Synthesis failed
2020-08-31 05:19:53,341 autosynth [DEBUG] > Running: git reset --hard HEAD
HEAD is now at bbfd9ec chore: update docstring format (#30)
2020-08-31 05:19:53,346 autosynth [DEBUG] > Running: git checkout autosynth
Switched to branch 'autosynth'
2020-08-31 05:19:53,351 autosynth [DEBUG] > Running: git clean -fdx
Removing __pycache__/
Removing google/__pycache__/
Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 690, in <module>
    main()
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 539, in main
    return _inner_main(temp_dir)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 670, in _inner_main
    commit_count = synthesize_loop(x, multiple_prs, change_pusher, synthesizer)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 375, in synthesize_loop
    has_changes = toolbox.synthesize_version_in_new_branch(synthesizer, youngest)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 273, in synthesize_version_in_new_branch
    synthesizer.synthesize(synth_log_path, self.environ)
  File "/tmpfs/src/github/synthtool/autosynth/synthesizer.py", line 120, in synthesize
    synth_proc.check_returncode()  # Raise an exception.
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 389, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']' returned non-zero exit status 1.

Google internal developers can see the full log here.

Synthesis failed for python-language

Hello! Autosynth couldn't regenerate python-language. ๐Ÿ’”

Here's the output from running synth.py:

oned repo /home/kbuilder/.cache/synthtool/synthtool
2021-01-21 05:43:27,516 synthtool [DEBUG] > Ensuring dependencies.
2021-01-21 05:43:27,526 synthtool [DEBUG] > Using precloned repo /home/kbuilder/.cache/synthtool/synthtool
2021-01-21 05:43:27,530 synthtool [DEBUG] > Cloning googleapis.
2021-01-21 05:43:27,530 synthtool [DEBUG] > Using precloned repo /home/kbuilder/.cache/synthtool/googleapis
2021-01-21 05:43:27,534 synthtool [DEBUG] > Generating code for: //google/cloud/language/v1beta2:language-v1beta2-py.
2021-01-21 05:43:28,631 synthtool [ERROR] > Failed executing bazel --max_idle_secs=240 build //google/cloud/language/v1beta2:language-v1beta2-py:

Loading: 
Loading: 0 packages loaded
DEBUG: /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/rules_python/python/pip.bzl:61:5: DEPRECATED: the pip_repositories rule has been replaced with pip_install, please see rules_python 0.1 release notes
Analyzing: target //google/cloud/language/v1beta2:language-v1beta2-py (1 packages loaded, 0 targets configured)
INFO: Analyzed target //google/cloud/language/v1beta2:language-v1beta2-py (1 packages loaded, 5 targets configured).
INFO: Found 1 target...
[0 / 4] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ERROR: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1beta2/BUILD.bazel:154:1: //google/cloud/language/v1beta2:language_py_gapic: `bazel-out/host/bin/external/com_google_protobuf/protoc --experimental_allow_proto3_optional --plugin=protoc-gen-python_gapic=bazel-out/host/bin/external/gapic_generator_python/gapic_plugin --python_gapic_out=retry-config=google/cloud/language/v1beta2/language_grpc_service_config.json:bazel-out/k8-fastbuild/bin/google/cloud/language/v1beta2/language_py_gapic.srcjar.zip -Igoogle/cloud/language/v1beta2/language_service.proto=google/cloud/language/v1beta2/language_service.proto -Igoogle/api/annotations.proto=google/api/annotations.proto -Igoogle/api/http.proto=google/api/http.proto -Igoogle/protobuf/descriptor.proto=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_imports/descriptor_proto/google/protobuf/descriptor.proto -Igoogle/api/client.proto=google/api/client.proto -Igoogle/api/field_behavior.proto=google/api/field_behavior.proto -Igoogle/protobuf/timestamp.proto=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_imports/timestamp_proto/google/protobuf/timestamp.proto google/cloud/language/v1beta2/language_service.proto` failed (Exit 1) protoc failed: error executing command bazel-out/host/bin/external/com_google_protobuf/protoc --experimental_allow_proto3_optional '--plugin=protoc-gen-python_gapic=bazel-out/host/bin/external/gapic_generator_python/gapic_plugin' ... (remaining 9 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
google/cloud/language/v1beta2/language_service.proto:23:1: warning: Import google/protobuf/timestamp.proto is unused.
Traceback (most recent call last):
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/cli/generate_with_pandoc.py", line 3, in <module>
    from gapic.cli import generate
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/cli/generate.py", line 23, in <module>
    from gapic import generator
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/generator/__init__.py", line 21, in <module>
    from .generator import Generator
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/generator/generator.py", line 24, in <module>
    from gapic.samplegen import manifest, samplegen
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/samplegen/__init__.py", line 15, in <module>
    from gapic.samplegen import samplegen
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/samplegen/samplegen.py", line 27, in <module>
    from gapic.schema import wrappers
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/schema/__init__.py", line 23, in <module>
    from gapic.schema.api import API
  File "/home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/sandbox/linux-sandbox/20/execroot/com_google_googleapis/bazel-out/host/bin/external/gapic_generator_python/gapic_plugin.runfiles/gapic_generator_python/gapic/schema/api.py", line 29, in <module>
    from google.api_core import exceptions  # type: ignore
ModuleNotFoundError: No module named 'google.api_core'
--python_gapic_out: protoc-gen-python_gapic: Plugin failed with status code 1.
Target //google/cloud/language/v1beta2:language-v1beta2-py failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.082s, Critical Path: 0.82s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 102, in <module>
    main()
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 94, in main
    spec.loader.exec_module(synth_module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/kbuilder/.cache/synthtool/python-language/synth.py", line 34, in <module>
    include_protos=True,
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 52, in py_library
    return self._generate_code(service, version, "python", **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 193, in _generate_code
    shell.run(bazel_run_args)
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 39, in run
    raise exc
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 33, in run
    encoding="utf-8",
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['bazel', '--max_idle_secs=240', 'build', '//google/cloud/language/v1beta2:language-v1beta2-py']' returned non-zero exit status 1.
2021-01-21 05:43:28,692 autosynth [ERROR] > Synthesis failed
2021-01-21 05:43:28,692 autosynth [DEBUG] > Running: git reset --hard HEAD
HEAD is now at 7d910d5 chore(deps): update dependency google-auth to v1.24.0 (#65)
2021-01-21 05:43:28,698 autosynth [DEBUG] > Running: git checkout autosynth
Switched to branch 'autosynth'
2021-01-21 05:43:28,703 autosynth [DEBUG] > Running: git clean -fdx
Removing __pycache__/
Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 354, in <module>
    main()
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 189, in main
    return _inner_main(temp_dir)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 334, in _inner_main
    commit_count = synthesize_loop(x, multiple_prs, change_pusher, synthesizer)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 65, in synthesize_loop
    has_changes = toolbox.synthesize_version_in_new_branch(synthesizer, youngest)
  File "/tmpfs/src/github/synthtool/autosynth/synth_toolbox.py", line 259, in synthesize_version_in_new_branch
    synthesizer.synthesize(synth_log_path, self.environ)
  File "/tmpfs/src/github/synthtool/autosynth/synthesizer.py", line 120, in synthesize
    synth_proc.check_returncode()  # Raise an exception.
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 389, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']' returned non-zero exit status 1.

Google internal developers can see the full log here.

ValueError: Protocol message Document has no "type" field.

Hello,

I've got an issue since I've passed my project to google-cloud-language 2.0.0.
I tried on the Cloud Shell Protocol offered by the official documentation. This bug appears everytime.

Environment details

  • OS type and version: MacOS - Catalina
  • Python version: Python 3.7.0
  • pip version: pip 20.2.4
  • google-cloud-language version: 2.0.0

pip freeze

asgiref==3.2.10
cachetools==4.0.0
certifi==2019.11.28
chardet==3.0.4
colorama==0.4.4
cygrpc==1.0.4.post6
google-api-core==1.23.0
google-api-python-client==1.12.4
google-auth==1.22.1
google-auth-httplib2==0.0.4
google-cloud==0.34.0
google-cloud-language==2.0.0
googleapis-common-protos==1.6.0
grpcio==1.31.0
grpcio-tools==1.23.0
idna==2.8
libcst==0.3.13
oauth2client==4.1.3
packaging==20.4
pkginfo==1.6.0
proto-plus==1.11.0
protobuf==3.13.0

Steps to reproduce

  1. I use the sample code of the library here : samples/v1/language_syntax_text.py
  2. python3 samples/v1/language_syntax_text.py

Code example

def gcl_analyze_syntax(sentence):
    client = language_v1.LanguageServiceClient()
    type_ = language_v1.Document.Type.PLAIN_TEXT
    language = "fr"
    document = {"content": sentence, "type": type_, "language": language}
    encoding_type = language_v1.EncodingType.UTF8
    tokens = client.analyze_syntax(request = {'document': document, 'encoding_type': encoding_type}).tokens
    return tokens

or

def sample_analyze_syntax(text_content):
    """
    Analyzing Syntax in a String
    Args:
      text_content The text content to analyze
    """

    client = language_v1.LanguageServiceClient()

    # text_content = 'This is a short sentence.'

    # Available types: PLAIN_TEXT, HTML
    type_ = language_v1.Document.Type.PLAIN_TEXT

    # Optional. If not specified, the language is automatically detected.
    # For list of supported languages:
    # https://cloud.google.com/natural-language/docs/languages
    language = "en"
    document = {"content": text_content, "type": type_, "language": language}

    # Available values: NONE, UTF8, UTF16, UTF32
    encoding_type = language_v1.EncodingType.UTF8

    response = client.analyze_syntax(request = {'document': document, 'encoding_type': encoding_type})

Stack trace

Traceback (most recent call last):
  File "samples/v1/language_syntax_text.py", line 110, in <module>
    main()
  File "samples/v1/language_syntax_text.py", line 106, in main
    sample_analyze_syntax(args.text_content)
  File "samples/v1/language_syntax_text.py", line 54, in sample_analyze_syntax
    response = client.analyze_syntax(request = {'document': document, 'encoding_type': encoding_type})
  File "/usr/local/lib/python3.7/dist-packages/google/cloud/language_v1/services/language_service/client.py", line 533, in analyze_syntax
    request = language_service.AnalyzeSyntaxRequest(request)
  File "/usr/local/lib/python3.7/dist-packages/proto/message.py", line 461, in __init__
    pb_value = marshal.to_proto(pb_type, value)
  File "/usr/local/lib/python3.7/dist-packages/proto/marshal/marshal.py", line 205, in to_proto
    pb_value = rule.to_proto(value)
  File "/usr/local/lib/python3.7/dist-packages/proto/marshal/rules/message.py", line 32, in to_proto
    return self._descriptor(**value)
ValueError: Protocol message Document has no "type" field.

Thanks,
Arthur

Empty response from analyze_sentiment using Dutch language

I am playing around with the Python SDK and think I've found a bug. Please review the following and let me know if you need any other details.

Environment details

  • Python 3.6.2 running Mac OS
  • Using google.cloud.language_v1

Steps to reproduce

  1. Send a Document to LanguageServiceClient -> analyze_sentiment
  2. Include a Dutch string
  3. Expect the response to be empty. The language is detected correctly, but no sentiment has been detected

Code example

document = language.types.Document(
                    content= "Dit is een nederlandse string. Vandaag is een super mooie dag.",
                    type=enums.Document.Type.PLAIN_TEXT
                    )
              
                sentiment = client.analyze_sentiment(document=document)
                
                print(sentiment)

Output

document_sentiment {
}
language: "nl"

Passing a langauge=nl parameter doesn't resolve the issue. I've tried other languages an that seems to work fine.

Synthesis failed for python-language

Hello! Autosynth couldn't regenerate python-language. ๐Ÿ’”

Here's the output from running synth.py:

w branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at f5e4c17 feat: Add include_protos parameter support for GAPICBazel (#489)
2020-06-20 08:21:05,919 autosynth [DEBUG] > Running: git branch -f autosynth-self-2
2020-06-20 08:21:05,923 autosynth [DEBUG] > Running: git checkout autosynth-self-2
Switched to branch 'autosynth-self-2'
2020-06-20 08:21:05,928 autosynth [INFO] > Running synthtool
2020-06-20 08:21:05,928 autosynth [INFO] > ['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']
2020-06-20 08:21:05,928 autosynth [DEBUG] > log_file_path: /tmpfs/src/github/synthtool/logs/googleapis/python-language/self/2/sponge_log.log
2020-06-20 08:21:05,930 autosynth [DEBUG] > Running: /tmpfs/src/github/synthtool/env/bin/python3 -m synthtool --metadata synth.metadata synth.py --
2020-06-20 08:21:06,133 synthtool [DEBUG] > Executing /home/kbuilder/.cache/synthtool/python-language/synth.py.
On branch autosynth-self-2
nothing to commit, working tree clean
2020-06-20 08:21:06,259 synthtool [DEBUG] > Ensuring dependencies.
2020-06-20 08:21:06,271 synthtool [DEBUG] > Using precloned repo /home/kbuilder/.cache/synthtool/synthtool
2020-06-20 08:21:06,275 synthtool [DEBUG] > Cloning googleapis.
2020-06-20 08:21:06,276 synthtool [DEBUG] > Using precloned repo /home/kbuilder/.cache/synthtool/googleapis
2020-06-20 08:21:06,279 synthtool [DEBUG] > Generating code for: //google/cloud/language/v1beta2:language-v1beta2-py.
2020-06-20 08:21:10,779 synthtool [ERROR] > Failed executing bazel --max_idle_secs=60 build //google/cloud/language/v1beta2:language-v1beta2-py:

Loading: 
Loading: 0 packages loaded
Loading: 0 packages loaded
Loading: 0 packages loaded
INFO: SHA256 (https://github.com/googleapis/gapic-generator/archive/4cb5d58f258afdb8abc0b99706370b4a59252b22.zip) = 3cb59685c8a4ae3db1dec60b286f22d8d3aa3d3b36bb08bf003b5e088fac83cb
DEBUG: Rule 'com_google_api_codegen' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "3cb59685c8a4ae3db1dec60b286f22d8d3aa3d3b36bb08bf003b5e088fac83cb"
DEBUG: Call stack for the definition of repository 'com_google_api_codegen' which is a http_archive (rule definition at /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/bazel_tools/tools/build_defs/repo/http.bzl:296:16):
 - <builtin>
 - /home/kbuilder/.cache/synthtool/googleapis/WORKSPACE:62:1
INFO: SHA256 (https://github.com/googleapis/protoc-java-resource-names-plugin/archive/5bd90a1f67c1c128291702cc320d667060f40f95.zip) = c3c0661b6c30fce5c63b1d5f473b1c6c4d59e19853ce3b9e8f5a447f953af906
DEBUG: Rule 'com_google_protoc_java_resource_names_plugin' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "c3c0661b6c30fce5c63b1d5f473b1c6c4d59e19853ce3b9e8f5a447f953af906"
DEBUG: Call stack for the definition of repository 'com_google_protoc_java_resource_names_plugin' which is a http_archive (rule definition at /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/bazel_tools/tools/build_defs/repo/http.bzl:296:16):
 - <builtin>
 - /home/kbuilder/.cache/synthtool/googleapis/WORKSPACE:155:1
Loading: 0 packages loaded
INFO: SHA256 (https://github.com/googleapis/gapic-generator-go/archive/v0.13.2.tar.gz) = ab7a2ffd74e6a6dac6da38027d4acadb84d0075c055289e3335d86a46f9f3b22
DEBUG: Rule 'com_googleapis_gapic_generator_go' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "ab7a2ffd74e6a6dac6da38027d4acadb84d0075c055289e3335d86a46f9f3b22"
DEBUG: Call stack for the definition of repository 'com_googleapis_gapic_generator_go' which is a http_archive (rule definition at /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/bazel_tools/tools/build_defs/repo/http.bzl:296:16):
 - <builtin>
 - /home/kbuilder/.cache/synthtool/googleapis/WORKSPACE:209:1
Analyzing: target //google/cloud/language/v1beta2:language-v1beta2-py (1 packages loaded, 0 targets configured)
INFO: Call stack for the definition of repository 'go_sdk' which is a _go_download_sdk (rule definition at /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/io_bazel_rules_go/go/private/sdk.bzl:79:20):
 - <builtin>
 - /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/io_bazel_rules_go/go/private/sdk.bzl:92:5
 - /home/kbuilder/.cache/bazel/_bazel_kbuilder/a732f932c2cbeb7e37e1543f189a2a73/external/io_bazel_rules_go/go/private/sdk.bzl:260:13
 - /home/kbuilder/.cache/synthtool/googleapis/WORKSPACE:81:1
ERROR: While resolving toolchains for target @pypi_black//:black: invalid registered toolchain '@gapic_generator_python//:pyenv3_toolchain': no such package '@gapic_generator_python//': The repository '@gapic_generator_python' could not be resolved
ERROR: Analysis of target '//google/cloud/language/v1beta2:language-v1beta2-py' failed; build aborted: invalid registered toolchain '@gapic_generator_python//:pyenv3_toolchain': no such package '@gapic_generator_python//': The repository '@gapic_generator_python' could not be resolved
INFO: Elapsed time: 4.488s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (29 packages loaded, 138 targets configured)
FAILED: Build did NOT complete successfully (29 packages loaded, 138 targets configured)

2020-06-20 08:21:10,780 synthtool [DEBUG] > Wrote metadata to synth.metadata.
Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 102, in <module>
    main()
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/github/synthtool/env/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 94, in main
    spec.loader.exec_module(synth_module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/kbuilder/.cache/synthtool/python-language/synth.py", line 33, in <module>
    include_protos=True,
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 46, in py_library
    return self._generate_code(service, version, "python", **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 180, in _generate_code
    shell.run(bazel_run_args)
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 39, in run
    raise exc
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 33, in run
    encoding="utf-8",
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['bazel', '--max_idle_secs=60', 'build', '//google/cloud/language/v1beta2:language-v1beta2-py']' returned non-zero exit status 1.
2020-06-20 08:21:10,826 autosynth [ERROR] > Synthesis failed
2020-06-20 08:21:10,826 autosynth [DEBUG] > Running: git reset --hard HEAD
HEAD is now at f16bd6d chore: Migrate python-languge synth.py from artman to bazel (#15)
2020-06-20 08:21:10,832 autosynth [DEBUG] > Running: git checkout autosynth-self
Switched to branch 'autosynth-self'
2020-06-20 08:21:10,837 autosynth [ERROR] > Command '['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']' returned non-zero exit status 1.
2020-06-20 08:21:11,018 autosynth [INFO] > PR already exists: https://github.com/googleapis/python-language/pull/21
2020-06-20 08:21:11,018 autosynth [DEBUG] > Running: git clean -fdx
Removing __pycache__/
Removing google/__pycache__/
Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 649, in <module>
    main()
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 506, in main
    return _inner_main(temp_dir)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 629, in _inner_main
    commit_count = synthesize_loop(x, multiple_prs, change_pusher, synthesizer)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 367, in synthesize_loop
    synthesize_inner_loop(fork, synthesizer)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 411, in synthesize_inner_loop
    synthesizer, len(toolbox.versions) - 1
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 266, in synthesize_version_in_new_branch
    synthesizer.synthesize(synth_log_path, self.environ)
  File "/tmpfs/src/github/synthtool/autosynth/synthesizer.py", line 120, in synthesize
    synth_proc.check_returncode()  # Raise an exception.
  File "/home/kbuilder/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 389, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']' returned non-zero exit status 1.

Google internal developers can see the full log here.

samples.snippets.generated-samples.v1.language_sentiment_text_test: test_analyze_sentiment_text_positive failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
args = (document {
  type_: PLAIN_TEXT
  content: "Happy Happy Joy Joy"
}
,)
kwargs = {'metadata': [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]}
@six.wraps(callable_)
def error_remapped_callable(*args, **kwargs):
    try:
      return callable_(*args, **kwargs)

.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:67:


self = <grpc._channel.UnaryUnaryMultiCallable object at 0x7f3ec952daf0>
request = document {
type
: PLAIN_TEXT
content: "Happy Happy Joy Joy"
}

timeout = None
metadata = [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]
credentials = None, wait_for_ready = None, compression = None

def __call__(self,
             request,
             timeout=None,
             metadata=None,
             credentials=None,
             wait_for_ready=None,
             compression=None):
    state, call, = self._blocking(request, timeout, metadata, credentials,
                                  wait_for_ready, compression)
  return _end_unary_response_blocking(state, call, False, None)

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:946:


state = <grpc._channel._RPCState object at 0x7f3ec94f2c10>
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f3ec84662c0>
with_call = False, deadline = None

def _end_unary_response_blocking(state, call, with_call, deadline):
    if state.code is grpc.StatusCode.OK:
        if with_call:
            rendezvous = _MultiThreadedRendezvous(state, call, None, deadline)
            return state.response, rendezvous
        else:
            return state.response
    else:
      raise _InactiveRpcError(state)

E grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
E status = StatusCode.UNAUTHENTICATED
E details = "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
E debug_error_string = "{"created":"@1626174404.132150381","description":"Error received from peer ipv4:74.125.20.95:443","file":"src/core/lib/surface/call.cc","file_line":1066,"grpc_message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
E >

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:849: _InactiveRpcError

The above exception was the direct cause of the following exception:

capsys = <_pytest.capture.CaptureFixture object at 0x7f3ec95236d0>

def test_analyze_sentiment_text_positive(capsys):
  language_sentiment_text.sample_analyze_sentiment("Happy Happy Joy Joy")

language_sentiment_text_test.py:20:


language_sentiment_text.py:42: in sample_analyze_sentiment
response = client.analyze_sentiment(request={'document': document})
../../../../google/cloud/language_v1/services/language_service/client.py:402: in analyze_sentiment
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py:145: in call
return wrapped_func(*args, **kwargs)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:285: in retry_wrapped_func
return retry_target(
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:188: in retry_target
return target()
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:69: in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)


value = None
from_value = <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request had invalid a...entication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"

???
E google.api_core.exceptions.Unauthenticated: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

:3: Unauthenticated

google-cloud-language ValueError: Protocol message Document has no "type" field.

I'm trying to extract named entities from text using Google Cloud Language python package in Python 3.7. When I attempt to run the example named entity extraction Python code from https://cloud.google.com/natural-language/docs/analyzing-entities#language-entities-file-python I get the following error:

ValueError: Protocol message Document has no "type" field.

This is the full stack trace:

File "/Users/user/google/example.py", line 60, in <module>
    print(sample_analyze_entities("California is a state."))

  File "/Users/user/google/example.py", line 26, in sample_analyze_entities
    response = client.analyze_entities(request = {'document': document, 'encoding_type': encoding_type})

  File "/Users/user/anaconda3/envs/env/lib/python3.7/site-packages/google/cloud/language_v1/services/language_service/client.py", line 381, in analyze_entities
    request = language_service.AnalyzeEntitiesRequest(request)

  File "/Users/users/anaconda3/envs/env/lib/python3.7/site-packages/proto/message.py", line 461, in __init__
    pb_value = marshal.to_proto(pb_type, value)

  File "/Users/user/anaconda3/envs/env/lib/python3.7/site-packages/proto/marshal/marshal.py", line 205, in to_proto
    pb_value = rule.to_proto(value)

  File "/Users/user/anaconda3/envs/env/lib/python3.7/site-packages/proto/marshal/rules/message.py", line 32, in to_proto
    return self._descriptor(**value)

ValueError: Protocol message Document has no "type" field.

The documentation shows that Document includes a "type" field: https://pub.dev/documentation/googleapis/latest/googleapis.language.v1/Document-class.html

I'm using the most up-to-date versions of google-cloud-language, setuptools and protobuf. The protocol error seems to have something to do with protobuf, which I am not very familiar with. Has anyone encountered a similar error and knows how to fix it?

Synthesis failed for python-language

Hello! Autosynth couldn't regenerate python-language. ๐Ÿ’”

Here's the output from running synth.py:

m_core.tp_print = 0;
                                                                                    ^~~~~~~~
                                                                                    tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132284:72: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_55__schedule_rpc_coro.tp_print = 0;
                                                                        ^~~~~~~~
                                                                        tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132290:65: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_56__handle_rpc.tp_print = 0;
                                                                 ^~~~~~~~
                                                                 tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132296:67: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_57__request_call.tp_print = 0;
                                                                   ^~~~~~~~
                                                                   tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132302:71: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_58__server_main_loop.tp_print = 0;
                                                                       ^~~~~~~~
                                                                       tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132308:59: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_59_start.tp_print = 0;
                                                           ^~~~~~~~
                                                           tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132314:74: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_60__start_shutting_down.tp_print = 0;
                                                                          ^~~~~~~~
                                                                          tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132320:62: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_61_shutdown.tp_print = 0;
                                                              ^~~~~~~~
                                                              tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:132326:74: error: 'PyTypeObject {aka struct _typeobject}' has no member named 'tp_print'; did you mean 'tp_dict'?
   __pyx_type_7_cython_6cygrpc___pyx_scope_struct_62_wait_for_termination.tp_print = 0;
                                                                          ^~~~~~~~
                                                                          tp_dict
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp: In function 'PyObject* __Pyx_decode_c_bytes(const char*, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char*, const char*, PyObject* (*)(const char*, Py_ssize_t, const char*))':
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:136866:45: warning: 'PyObject* PyUnicode_FromUnicode(const Py_UNICODE*, Py_ssize_t)' is deprecated [-Wdeprecated-declarations]
         return PyUnicode_FromUnicode(NULL, 0);
                                             ^
In file included from bazel-out/host/bin/external/local_config_python/_python3/_python3_include/unicodeobject.h:1026:0,
                 from bazel-out/host/bin/external/local_config_python/_python3/_python3_include/Python.h:97,
                 from bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:4:
bazel-out/host/bin/external/local_config_python/_python3/_python3_include/cpython/unicodeobject.h:551:42: note: declared here
 Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
                                          ^~~~~~~~~~~~~~~~~~~~~
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp: In function 'void __pyx_f_7_cython_6cygrpc__unified_socket_write(int)':
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:72692:3: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]
   (void)(write(__pyx_v_fd, ((char *)"1"), 1));
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp: At global scope:
bazel-out/host/bin/external/com_github_grpc_grpc/src/python/grpcio/grpc/_cython/cygrpc.cpp:144607:1: warning: 'void __Pyx_PyAsyncGen_Fini()' defined but not used [-Wunused-function]
 __Pyx_PyAsyncGen_Fini(void)
 ^~~~~~~~~~~~~~~~~~~~~
Target //google/cloud/language/v1beta2:language-v1beta2-py failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4.159s, Critical Path: 3.88s
INFO: 7 processes: 7 linux-sandbox.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 102, in <module>
    main()
  File "/tmpfs/src/github/synthtool/env/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/env/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/github/synthtool/env/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/github/synthtool/env/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/__main__.py", line 94, in main
    spec.loader.exec_module(synth_module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/root/.cache/synthtool/python-language/synth.py", line 30, in <module>
    library = gapic.py_library(
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 45, in py_library
    return self._generate_code(service, version, "python", **kwargs)
  File "/tmpfs/src/github/synthtool/synthtool/gcp/gapic_bazel.py", line 182, in _generate_code
    shell.run(bazel_run_args)
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 39, in run
    raise exc
  File "/tmpfs/src/github/synthtool/synthtool/shell.py", line 27, in run
    return subprocess.run(
  File "/usr/local/lib/python3.9/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['bazel', '--max_idle_secs=240', 'build', '//google/cloud/language/v1beta2:language-v1beta2-py']' returned non-zero exit status 1.
2020-12-05 03:07:48,841 autosynth [ERROR] > Synthesis failed
2020-12-05 03:07:48,842 autosynth [DEBUG] > Running: git reset --hard HEAD
HEAD is now at 8c9fdeb chore(deps): update dependency google-api-python-client to v1.12.8 (#54)
2020-12-05 03:07:48,847 autosynth [DEBUG] > Running: git checkout autosynth
Switched to branch 'autosynth'
2020-12-05 03:07:48,853 autosynth [DEBUG] > Running: git clean -fdx
Removing __pycache__/
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 354, in <module>
    main()
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 189, in main
    return _inner_main(temp_dir)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 334, in _inner_main
    commit_count = synthesize_loop(x, multiple_prs, change_pusher, synthesizer)
  File "/tmpfs/src/github/synthtool/autosynth/synth.py", line 65, in synthesize_loop
    has_changes = toolbox.synthesize_version_in_new_branch(synthesizer, youngest)
  File "/tmpfs/src/github/synthtool/autosynth/synth_toolbox.py", line 259, in synthesize_version_in_new_branch
    synthesizer.synthesize(synth_log_path, self.environ)
  File "/tmpfs/src/github/synthtool/autosynth/synthesizer.py", line 120, in synthesize
    synth_proc.check_returncode()  # Raise an exception.
  File "/usr/local/lib/python3.9/subprocess.py", line 456, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '['/tmpfs/src/github/synthtool/env/bin/python3', '-m', 'synthtool', '--metadata', 'synth.metadata', 'synth.py', '--']' returned non-zero exit status 1.

Google internal developers can see the full log here.

The script is stuck/hanging in AWS Beanstalk

I'm trying to use Google Cloud NLP, it works well on Windows localhost, but when i use it in Beanstalk the script is stuck when it reaches the line below and i have to restart the server again.

sentiment = client.analyze_sentiment(document=document).document_sentiment

here is all the scripts I'm using:

from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types

# Instantiates a client
client = language.LanguageServiceClient()

# The text to analyze
text = u'Hello, world!'
document = types.Document(
    content=text,
    type=enums.Document.Type.PLAIN_TEXT)

# Detects the sentiment of the text
sentiment = client.analyze_sentiment(document=document).document_sentiment

print('Text: {}'.format(text))
print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))

samples.snippets.api.analyze_test: test_analyze_entities failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
def test_analyze_entities():
        result = analyze.analyze_entities(
>           "Tom Sawyer is a book written by a guy known as Mark Twain."
        )

analyze_test.py:21:


analyze.py:43: in analyze_entities
response = request.execute()
.nox/py-3-7/lib/python3.7/site-packages/googleapiclient/_helpers.py:134: in positional_wrapper
return wrapped(*args, **kwargs)
.nox/py-3-7/lib/python3.7/site-packages/googleapiclient/http.py:929: in execute
headers=self.headers,
.nox/py-3-7/lib/python3.7/site-packages/googleapiclient/http.py:191: in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
.nox/py-3-7/lib/python3.7/site-packages/google_auth_httplib2.py:209: in request
self.credentials.before_request(self._request, method, uri, request_headers)
.nox/py-3-7/lib/python3.7/site-packages/google/auth/credentials.py:133: in before_request
self.refresh(request)
.nox/py-3-7/lib/python3.7/site-packages/google/oauth2/service_account.py:408: in refresh
request, self._token_uri, assertion
.nox/py-3-7/lib/python3.7/site-packages/google/oauth2/_client.py:193: in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
.nox/py-3-7/lib/python3.7/site-packages/google/oauth2/_client.py:165: in _token_endpoint_request
_handle_error_response(response_data)


response_data = {'error': 'invalid_grant', 'error_description': 'Invalid JWT Signature.'}

def _handle_error_response(response_data):
    """Translates an error response into an exception.

    Args:
        response_data (Mapping): The decoded response data.

    Raises:
        google.auth.exceptions.RefreshError: The errors contained in response_data.
    """
    try:
        error_details = "{}: {}".format(
            response_data["error"], response_data.get("error_description")
        )
    # If no details could be extracted, use the response data.
    except (KeyError, ValueError):
        error_details = json.dumps(response_data)
  raise exceptions.RefreshError(error_details, response_data)

E google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT Signature.', {'error': 'invalid_grant', 'error_description': 'Invalid JWT Signature.'})

.nox/py-3-7/lib/python3.7/site-packages/google/oauth2/_client.py:60: RefreshError

samples.snippets.cloud-client.v1.set_endpoint_test: test_set_endpoint failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: 4a47bc7
buildURL: Build Status, Sponge
status: failed

Test output
args = (document {
  type_: PLAIN_TEXT
  content: "Hello, world!"
}
,)
kwargs = {'metadata': [('x-goog-api-client', 'gl-python/3.6.13 grpc/1.39.0 gax/2.0.1 gapic/2.2.2')]}
@functools.wraps(callable_)
def error_remapped_callable(*args, **kwargs):
    try:
      return callable_(*args, **kwargs)

.nox/py-3-6/lib/python3.6/site-packages/google/api_core/grpc_helpers.py:66:


self = <grpc._channel.UnaryUnaryMultiCallable object at 0x7f696235cc88>
request = document {
type
: PLAIN_TEXT
content: "Hello, world!"
}

timeout = None
metadata = [('x-goog-api-client', 'gl-python/3.6.13 grpc/1.39.0 gax/2.0.1 gapic/2.2.2')]
credentials = None, wait_for_ready = None, compression = None

def __call__(self,
             request,
             timeout=None,
             metadata=None,
             credentials=None,
             wait_for_ready=None,
             compression=None):
    state, call, = self._blocking(request, timeout, metadata, credentials,
                                  wait_for_ready, compression)
  return _end_unary_response_blocking(state, call, False, None)

.nox/py-3-6/lib/python3.6/site-packages/grpc/_channel.py:946:


state = <grpc._channel._RPCState object at 0x7f6960ade048>
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f6962364788>
with_call = False, deadline = None

def _end_unary_response_blocking(state, call, with_call, deadline):
    if state.code is grpc.StatusCode.OK:
        if with_call:
            rendezvous = _MultiThreadedRendezvous(state, call, None, deadline)
            return state.response, rendezvous
        else:
            return state.response
    else:
      raise _InactiveRpcError(state)

E grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
E status = StatusCode.INTERNAL
E details = "Internal error encountered."
E debug_error_string = "{"created":"@1631005656.714801512","description":"Error received from peer ipv4:108.177.98.95:443","file":"src/core/lib/surface/call.cc","file_line":1069,"grpc_message":"Internal error encountered.","grpc_status":13}"
E >

.nox/py-3-6/lib/python3.6/site-packages/grpc/_channel.py:849: _InactiveRpcError

The above exception was the direct cause of the following exception:

capsys = <_pytest.capture.CaptureFixture object at 0x7f696417e470>

def test_set_endpoint(capsys):
  set_endpoint.set_endpoint()

set_endpoint_test.py:19:


set_endpoint.py:34: in set_endpoint
sentiment = client.analyze_sentiment(request={'document': document}).document_sentiment
../../../../google/cloud/language_v1/services/language_service/client.py:406: in analyze_sentiment
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
.nox/py-3-6/lib/python3.6/site-packages/google/api_core/gapic_v1/method.py:142: in call
return wrapped_func(*args, **kwargs)
.nox/py-3-6/lib/python3.6/site-packages/google/api_core/retry.py:288: in retry_wrapped_func
on_error=on_error,
.nox/py-3-6/lib/python3.6/site-packages/google/api_core/retry.py:190: in retry_target
return target()


args = (document {
type_: PLAIN_TEXT
content: "Hello, world!"
}
,)
kwargs = {'metadata': [('x-goog-api-client', 'gl-python/3.6.13 grpc/1.39.0 gax/2.0.1 gapic/2.2.2')]}

@functools.wraps(callable_)
def error_remapped_callable(*args, **kwargs):
    try:
        return callable_(*args, **kwargs)
    except grpc.RpcError as exc:
      raise exceptions.from_grpc_error(exc) from exc

E google.api_core.exceptions.InternalServerError: 500 Internal error encountered.

.nox/py-3-6/lib/python3.6/site-packages/google/api_core/grpc_helpers.py:68: InternalServerError

module 'google.api_core' has no attribute 'gapic_v1'

I used to have ImportError: cannot import name 'aio' so I upgraded grpcio and google-api-core and pin google-api-python-client to 1.11.0.
This worked well until last week the google cloud language api reports AttributeError : module 'google.api_core' has no attribute 'gapic_v1'

Environment details

  • Python version: python 3.7
- google-api-core==1.22.2
- google-api-python-client==1.11.0
- google-apitools==0.5.30
- google-auth==1.21.2
- google-auth-httplib2==0.0.3
- google-auth-oauthlib==0.4.0
- google-cloud-bigquery==1.8.1
- google-cloud-bigtable==0.32.0
- google-cloud-container==0.2.1
- google-cloud-core==0.29.1
- google-cloud-language==1.3.0
- google-cloud-logging==1.9.1
- google-cloud-monitoring==0.31.1
- google-cloud-spanner==1.8.0
- google-cloud-storage==1.13.2
- google-cloud-translate==1.4.0
- google-cloud-vision==0.39.0
- google-resumable-media==0.3.2
- googleapis-common-protos==1.52.0
- grpc-google-iam-v1==0.11.4
- pydata-google-auth==0.1.3
- grpcio==1.23.0
- grpcio-gcp==0.2.2

Stack trace

  File "/tmp/airflowtmpfvgzw4al/bq_fonctions.py", line 20, in <module>
    import fonctions as fc
  File "/tmp/airflowtmpfvgzw4al/fonctions.py", line 28, in <module>
    from google.cloud import language
  File "/opt/python3.6/lib/python3.6/site-packages/google/cloud/language.py", line 17, in <module>
    from google.cloud.language_v1 import LanguageServiceClient
  File "/opt/python3.6/lib/python3.6/site-packages/google/cloud/language_v1/__init__.py", line 19, in <module>
    from google.cloud.language_v1.gapic import language_service_client
  File "/opt/python3.6/lib/python3.6/site-packages/google/cloud/language_v1/gapic/language_service_client.py", line 40, in <module>
    class LanguageServiceClient(object):
  File "/opt/python3.6/lib/python3.6/site-packages/google/cloud/language_v1/gapic/language_service_client.py", line 190, in LanguageServiceClient
    retry=google.api_core.gapic_v1.method.DEFAULT,
AttributeError: module 'google.api_core' has no attribute 'gapic_v1'

samples.snippets.api.analyze_test: test_analyze_syntax failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
capsys = <_pytest.capture.CaptureFixture object at 0x7f80b514af98>
def test_analyze_syntax(capsys):
    result = analyze.analyze_syntax(
        textwrap.dedent(
            u"""\
        Keep away from people who try to belittle your ambitions. Small people
        always do that, but the really great make you feel that you, too, can
        become great.
      - Mark Twain"""
        )
    )

analyze_test.py:55:


analyze.py:71: in analyze_syntax
response = request.execute()
.nox/py-3-6/lib/python3.6/site-packages/googleapiclient/_helpers.py:134: in positional_wrapper
return wrapped(*args, **kwargs)
.nox/py-3-6/lib/python3.6/site-packages/googleapiclient/http.py:929: in execute
headers=self.headers,
.nox/py-3-6/lib/python3.6/site-packages/googleapiclient/http.py:191: in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
.nox/py-3-6/lib/python3.6/site-packages/google_auth_httplib2.py:209: in request
self.credentials.before_request(self._request, method, uri, request_headers)
.nox/py-3-6/lib/python3.6/site-packages/google/auth/credentials.py:133: in before_request
self.refresh(request)
.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/service_account.py:408: in refresh
request, self._token_uri, assertion
.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/_client.py:193: in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/_client.py:165: in _token_endpoint_request
_handle_error_response(response_data)


response_data = {'error': 'invalid_grant', 'error_description': 'Invalid JWT Signature.'}

def _handle_error_response(response_data):
    """Translates an error response into an exception.

    Args:
        response_data (Mapping): The decoded response data.

    Raises:
        google.auth.exceptions.RefreshError: The errors contained in response_data.
    """
    try:
        error_details = "{}: {}".format(
            response_data["error"], response_data.get("error_description")
        )
    # If no details could be extracted, use the response data.
    except (KeyError, ValueError):
        error_details = json.dumps(response_data)
  raise exceptions.RefreshError(error_details, response_data)

E google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT Signature.', {'error': 'invalid_grant', 'error_description': 'Invalid JWT Signature.'})

.nox/py-3-6/lib/python3.6/site-packages/google/oauth2/_client.py:60: RefreshError

The returned wiki url in response object by calling analyze_entities references to Non-English Wikipedia page

Hello,

The returned wiki url in response object by calling analyze_entities references to Non-English Wikipedia page. I think this method functioned properly before, i.e., always referencing to English Wikipedia page. However, it starts returning non-English wiki URLs right now. Please check details below.

Environment details

  • OS type and version: Ubuntu 20.04.4 LTS
  • Python version: python 3.9.7
  • pip version: pip 22.0.3
  • google-cloud-language version: google-cloud-language Version: 2.4.1

Steps to reproduce

from google.cloud import language_v1
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "AUTHENTICATION PRIVATE KEY"
client = language_v1.LanguageServiceClient()
text_content = "USA"
type_ = language_v1.Document.Type.PLAIN_TEXT
language = "en"
document = {"content": text_content, "type_": type_, "language": language}
encoding_type = language_v1.EncodingType.UTF32
response = client.analyze_entities(request = {'document': document, 'encoding_type': encoding_type})

Code example

The returned response object correctly recognizes the correct entity (USA), but references to non-English wiki URL even though I have specified "en" for the language option.

entities {
  name: "USA"
  type_: LOCATION
  metadata {
    key: "mid"
    value: "/m/09c7w0"
  }
  metadata {
    key: "wikipedia_url"
    value: "https://de.wikipedia.org/wiki/Vereinigte_Staaten"
  }
  salience: 1.0
  mentions {
    text {
      content: "USA"
    }
    type_: PROPER
  }
}
language: "en"

The error is also reproducible on your online demo. Please take a look at the url circled by me in the following screenshot.
image

Is there a way to revert the current release to an older version or revert your database?
Thanks!

Synthesis failed for python-language

Hello! Autosynth couldn't regenerate python-language. ๐Ÿ’”

Here's the output from running synth.py:

Cloning into 'working_repo'...
Switched to branch 'autosynth'
Running synthtool
['/tmpfs/src/git/autosynth/env/bin/python3', '-m', 'synthtool', 'synth.py', '--']
synthtool > Executing /tmpfs/src/git/autosynth/working_repo/synth.py.
On branch autosynth
nothing to commit, working tree clean
HEAD detached at FETCH_HEAD
nothing to commit, working tree clean
synthtool > Ensuring dependencies.
synthtool > Pulling artman image.
latest: Pulling from googleapis/artman
Digest: sha256:6aec9c34db0e4be221cdaf6faba27bdc07cfea846808b3d3b964dfce3a9a0f9b
Status: Image is up to date for googleapis/artman:latest
synthtool > Cloning googleapis.
synthtool > Running generator for google/cloud/language/artman_language_v1beta2.yaml.
synthtool > Generated code into /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1beta2.
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1beta2/language_service.proto to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1beta2/google/cloud/language_v1beta2/proto/language_service.proto
synthtool > Placed proto files into /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1beta2/google/cloud/language_v1beta2/proto.
synthtool > No files in sources /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1beta2/samples were copied. Does the source contain files?
synthtool > Running generator for google/cloud/language/artman_language_v1.yaml.
synthtool > Generated code into /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1.
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1/language_service.proto to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/google/cloud/language_v1/proto/language_service.proto
synthtool > Placed proto files into /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/google/cloud/language_v1/proto.
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1/samples/test/analyzing_sentiment.test.yaml to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/samples/v1/test/analyzing_sentiment.test.yaml
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1/samples/test/analyzing_entity_sentiment.test.yaml to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/samples/v1/test/analyzing_entity_sentiment.test.yaml
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1/samples/test/analyzing_syntax.test.yaml to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/samples/v1/test/analyzing_syntax.test.yaml
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1/samples/test/analyzing_entities.test.yaml to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/samples/v1/test/analyzing_entities.test.yaml
synthtool > Copy: /home/kbuilder/.cache/synthtool/googleapis/google/cloud/language/v1/samples/test/classifying_content.test.yaml to /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/samples/v1/test/classifying_content.test.yaml
synthtool > Writing samples manifest ['gen-manifest', '--env=python', '--bin=python3', '--output=v1/test/samples.manifest.yaml', '--chdir={@manifest_dir}/../..', 'v1/language_entity_sentiment_gcs.py', 'v1/language_classify_gcs.py', 'v1/language_syntax_gcs.py', 'v1/language_entities_text.py', 'v1/language_classify_text.py', 'v1/language_syntax_text.py', 'v1/language_entity_sentiment_text.py', 'v1/language_entities_gcs.py', 'v1/language_sentiment_gcs.py', 'v1/language_sentiment_text.py']
synthtool > No files in sources /home/kbuilder/.cache/synthtool/googleapis/artman-genfiles/python/language-v1/tests/system/gapic/v1 were copied. Does the source contain files?
.coveragerc
.flake8
.github/CONTRIBUTING.md
.github/ISSUE_TEMPLATE/bug_report.md
.github/ISSUE_TEMPLATE/feature_request.md
.github/ISSUE_TEMPLATE/support_request.md
.github/PULL_REQUEST_TEMPLATE.md
.github/release-please.yml
.gitignore
.kokoro/build.sh
.kokoro/continuous/common.cfg
.kokoro/continuous/continuous.cfg
.kokoro/docs/common.cfg
.kokoro/docs/docs.cfg
.kokoro/presubmit/common.cfg
.kokoro/presubmit/presubmit.cfg
.kokoro/publish-docs.sh
.kokoro/release.sh
.kokoro/release/common.cfg
.kokoro/release/release.cfg
.kokoro/trampoline.sh
CODE_OF_CONDUCT.md
CONTRIBUTING.rst
LICENSE
MANIFEST.in
docs/_static/custom.css
docs/_templates/layout.html
docs/conf.py.j2
noxfile.py.j2
renovate.json
setup.cfg
synthtool > Replaced '__doc__ = """################################################################\n  #\n  \n  Represents the input to API methods.' in google/cloud/language_v1/proto/language_service_pb2.py.
synthtool > Replaced '__doc__ = """################################################################\n  #\n  \n  Represents the input to API methods.' in google/cloud/language_v1beta2/proto/language_service_pb2.py.
synthtool > Replaced 'types\\.EncodingType' in google/cloud/language_v1/gapic/language_service_client.py.
synthtool > Replaced 'types\\.EncodingType' in google/cloud/language_v1beta2/gapic/language_service_client.py.
Running session blacken
Creating virtual environment (virtualenv) using python3.6 in .nox/blacken
pip install black==19.3b0
Error: pip is not installed into the virtualenv, it is located at /tmpfs/src/git/autosynth/env/bin/pip. Pass external=True into run() to explicitly allow this.
Session blacken failed.
synthtool > Failed executing nox -s blacken:

None
synthtool > Wrote metadata to synth.metadata.
Traceback (most recent call last):
  File "/home/kbuilder/.pyenv/versions/3.6.1/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/kbuilder/.pyenv/versions/3.6.1/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/synthtool/__main__.py", line 102, in <module>
    main()
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/synthtool/__main__.py", line 94, in main
    spec.loader.exec_module(synth_module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/tmpfs/src/git/autosynth/working_repo/synth.py", line 63, in <module>
    s.shell.run(["nox", "-s", "blacken"], hide_output=False)
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/synthtool/shell.py", line 39, in run
    raise exc
  File "/tmpfs/src/git/autosynth/env/lib/python3.6/site-packages/synthtool/shell.py", line 33, in run
    encoding="utf-8",
  File "/home/kbuilder/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 418, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['nox', '-s', 'blacken']' returned non-zero exit status 1.

Synthesis failed

Google internal developers can see the full log here.

google.api_core.exceptions.ServiceUnavailable: 503 Getting metadata from plugin failed with error: None could not be converted to unicode

Environment details

  • OS type and version: Ubuntu 20.04
  • Python version: Python 3.9.14
  • pip version: pip 22.2.2
  • google-cloud-language version:
Name: google-cloud-language
Version: 2.6.1
Summary: Google Cloud Natural Language API client library
Home-page: https://github.com/googleapis/python-language
Author: Google LLC
Author-email: [email protected]
License: Apache 2.0
Location: /home/jakub/.cache/pypoetry/virtualenvs/predict-api-python-58y2ik0X-py3.9/lib/python3.9/site-packages
Requires: google-api-core, proto-plus, protobuf
Required-by: 

Steps to reproduce

Run this simple async hello world example:

import asyncio
import os

from google.cloud import language_v1
from google.cloud.language_v1 import Document, EncodingType

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "credentials.json"


async def sample_analyze_sentiment():
    # Create a client
    client = language_v1.LanguageServiceAsyncClient()

    texts = ["Good morning", "Hello there", "General Kenobi"]

    documents = [
        {
            "content": text,
            "type_": Document.Type.PLAIN_TEXT,
            "language": "en",
        }
        for text in texts
    ]

    requests = [
        {"document": document, "encoding_type": EncodingType.UTF8}
        for document in documents
    ]

    tasks = [client.analyze_sentiment(request) for request in requests]

    response = await asyncio.gather(*tasks)

    # Handle the response
    print(response)


asyncio.run(sample_analyze_sentiment())

I get errors about 80% of time, but sometimes (randomly) it works and I get result:

[document_sentiment {
  magnitude: 0.8
  score: 0.8
}
language: "en"
sentences {
  text {
    content: "Good morning"
  }
  sentiment {
    magnitude: 0.8
    score: 0.8
  }
}
, document_sentiment {
  magnitude: 0.3
  score: 0.3
}
language: "en"
sentences {
  text {
    content: "Hello there"
  }
  sentiment {
    magnitude: 0.3
    score: 0.3
  }
}
, document_sentiment {
  magnitude: 0.1
  score: 0.1
}
language: "en"
sentences {
  text {
    content: "General Kenobi"
  }
  sentiment {
    magnitude: 0.1
    score: 0.1
  }
}
]

It always works when I use a single element await, instead of gather:

# tasks = [client.analyze_sentiment(request) for request in requests]
response = await client.analyze_sentiment(requests[0])

Stack trace

Traceback (most recent call last):
  File "/home/jakub/.cache/pypoetry/virtualenvs/predict-api-python-58y2ik0X-py3.9/lib/python3.9/site-packages/google/api_core/grpc_helpers_async.py", line 81, in __await__
    response = yield from self._call.__await__()
  File "/home/jakub/.cache/pypoetry/virtualenvs/predict-api-python-58y2ik0X-py3.9/lib/python3.9/site-packages/grpc/aio/_call.py", line 290, in __await__
    raise _create_rpc_error(self._cython_call._initial_metadata,
grpc.aio._call.AioRpcError: <AioRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "Getting metadata from plugin failed with error: None could not be converted to unicode"
	debug_error_string = "UNKNOWN:Error received from peer language.googleapis.com:443 {created_time:"2022-11-15T13:52:42.29405481+01:00", grpc_status:14, grpc_message:"Getting metadata from plugin failed with error: None could not be converted to unicode"}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/jakub/PycharmProjects/predict_api_python/tmp.py", line 38, in <module>
    asyncio.run(sample_analyze_sentiment())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/home/jakub/PycharmProjects/predict_api_python/tmp.py", line 32, in sample_analyze_sentiment
    response = await asyncio.gather(*tasks)
  File "/home/jakub/.cache/pypoetry/virtualenvs/predict-api-python-58y2ik0X-py3.9/lib/python3.9/site-packages/google/cloud/language_v1/services/language_service/async_client.py", line 312, in analyze_sentiment
    response = await rpc(
  File "/home/jakub/.cache/pypoetry/virtualenvs/predict-api-python-58y2ik0X-py3.9/lib/python3.9/site-packages/google/api_core/grpc_helpers_async.py", line 84, in __await__
    raise exceptions.from_grpc_error(rpc_error) from rpc_error
google.api_core.exceptions.ServiceUnavailable: 503 Getting metadata from plugin failed with error: None could not be converted to unicode

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

This repository currently has no open or pending branches.


  • Check this box to trigger a request for Renovate to run again on this repository

samples.snippets.classify_text.classify_text_tutorial_test: test_query_text failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
args = (document {
  type_: PLAIN_TEXT
  content: "Google Home enables users to speak voice commands to interact\nwith servic...egrated, allowing users to listen to music, look at videos or photos,\nor receive news updates entirely by voice."
}
,)
kwargs = {'metadata': [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]}
@six.wraps(callable_)
def error_remapped_callable(*args, **kwargs):
    try:
      return callable_(*args, **kwargs)

.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:67:


self = <grpc._channel.UnaryUnaryMultiCallable object at 0x7f3110550070>
request = document {
type
: PLAIN_TEXT
content: "Google Home enables users to speak voice commands to interact\nwith service...ntegrated, allowing users to listen to music, look at videos or photos,\nor receive news updates entirely by voice."
}

timeout = None
metadata = [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]
credentials = None, wait_for_ready = None, compression = None

def __call__(self,
             request,
             timeout=None,
             metadata=None,
             credentials=None,
             wait_for_ready=None,
             compression=None):
    state, call, = self._blocking(request, timeout, metadata, credentials,
                                  wait_for_ready, compression)
  return _end_unary_response_blocking(state, call, False, None)

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:946:


state = <grpc._channel._RPCState object at 0x7f3110550820>
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f3110547fc0>
with_call = False, deadline = None

def _end_unary_response_blocking(state, call, with_call, deadline):
    if state.code is grpc.StatusCode.OK:
        if with_call:
            rendezvous = _MultiThreadedRendezvous(state, call, None, deadline)
            return state.response, rendezvous
        else:
            return state.response
    else:
      raise _InactiveRpcError(state)

E grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
E status = StatusCode.UNAUTHENTICATED
E details = "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
E debug_error_string = "{"created":"@1626174380.453868481","description":"Error received from peer ipv4:74.125.20.95:443","file":"src/core/lib/surface/call.cc","file_line":1066,"grpc_message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
E >

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:849: _InactiveRpcError

The above exception was the direct cause of the following exception:

capsys = <_pytest.capture.CaptureFixture object at 0x7f3111dcfcd0>
index_file = local('/tmp/pytest-of-root/pytest-0/tmp0/index.json')

def test_query_text(capsys, index_file):
    temp_out = index_file.strpath
  classify_text_tutorial.query(temp_out, QUERY_TEXT)

classify_text_tutorial_test.py:61:


classify_text_tutorial.py:159: in query
query_categories = classify(text, verbose=False)
classify_text_tutorial.py:45: in classify
response = language_client.classify_text(request={'document': document})
../../../google/cloud/language_v1/services/language_service/client.py:686: in classify_text
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py:145: in call
return wrapped_func(*args, **kwargs)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:285: in retry_wrapped_func
return retry_target(
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:188: in retry_target
return target()
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:69: in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)


value = None
from_value = <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request had invalid a...entication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"

???
E google.api_core.exceptions.Unauthenticated: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

:3: Unauthenticated

samples.snippets.generated-samples.v1.language_sentiment_text_test: test_analyze_sentiment_text_negative failed

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: cb9751e
buildURL: Build Status, Sponge
status: failed

Test output
args = (document {
  type_: PLAIN_TEXT
  content: "Angry Angry Sad Sad"
}
,)
kwargs = {'metadata': [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]}
@six.wraps(callable_)
def error_remapped_callable(*args, **kwargs):
    try:
      return callable_(*args, **kwargs)

.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:67:


self = <grpc._channel.UnaryUnaryMultiCallable object at 0x7f3ec8403910>
request = document {
type
: PLAIN_TEXT
content: "Angry Angry Sad Sad"
}

timeout = None
metadata = [('x-goog-api-client', 'gl-python/3.8.8 grpc/1.38.1 gax/1.31.0 gapic/2.2.0')]
credentials = None, wait_for_ready = None, compression = None

def __call__(self,
             request,
             timeout=None,
             metadata=None,
             credentials=None,
             wait_for_ready=None,
             compression=None):
    state, call, = self._blocking(request, timeout, metadata, credentials,
                                  wait_for_ready, compression)
  return _end_unary_response_blocking(state, call, False, None)

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:946:


state = <grpc._channel._RPCState object at 0x7f3ec8403fa0>
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f3ec826a200>
with_call = False, deadline = None

def _end_unary_response_blocking(state, call, with_call, deadline):
    if state.code is grpc.StatusCode.OK:
        if with_call:
            rendezvous = _MultiThreadedRendezvous(state, call, None, deadline)
            return state.response, rendezvous
        else:
            return state.response
    else:
      raise _InactiveRpcError(state)

E grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
E status = StatusCode.UNAUTHENTICATED
E details = "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
E debug_error_string = "{"created":"@1626174404.335058039","description":"Error received from peer ipv4:74.125.20.95:443","file":"src/core/lib/surface/call.cc","file_line":1066,"grpc_message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
E >

.nox/py-3-8/lib/python3.8/site-packages/grpc/_channel.py:849: _InactiveRpcError

The above exception was the direct cause of the following exception:

capsys = <_pytest.capture.CaptureFixture object at 0x7f3ec83aad90>

def test_analyze_sentiment_text_negative(capsys):
  language_sentiment_text.sample_analyze_sentiment("Angry Angry Sad Sad")

language_sentiment_text_test.py:26:


language_sentiment_text.py:42: in sample_analyze_sentiment
response = client.analyze_sentiment(request={'document': document})
../../../../google/cloud/language_v1/services/language_service/client.py:402: in analyze_sentiment
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py:145: in call
return wrapped_func(*args, **kwargs)
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:285: in retry_wrapped_func
return retry_target(
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/retry.py:188: in retry_target
return target()
.nox/py-3-8/lib/python3.8/site-packages/google/api_core/grpc_helpers.py:69: in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)


value = None
from_value = <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request had invalid a...entication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"

???
E google.api_core.exceptions.Unauthenticated: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

:3: Unauthenticated

.github/.OwlBot.lock.yaml is broken.

This repo will not receive automatic updates until this issue is fixed.

  • YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (19:1)

16 | digest: sha256:f62c53736eccb0 ...
17 |
18 | trigger ci
19 |
------^

How to properly import Python google.cloud.language SDK?

I'm trying to implement entity sentiment analysis using Google's Natural Language API:

from google.cloud import language

client = language.LanguageServiceClient.from_service_account_json('credentials.json')
document = language.types.Document(
    content='Mona said that jogging is very fun.',
    type='PLAIN_TEXT')

However, I get the following error:

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.8/site-packages/proto/message.py", line 457, in __init__
    pb_type = self._meta.fields[key].pb_type
KeyError: 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/lib/python3.8/site-packages/proto/message.py", line 462, in __init__
    raise ValueError(
ValueError: Unknown field for Document: type

How can I solve this error? I've tried from google.cloud import language_v1 as language to no avail. For reference, google-cloud==0.34.0.

AttributeError: module 'google.cloud.language_v1' has no attribute 'PartOfSpeech'

Hi,

I'm using the sample code provided at the documentation to analyze_syntax, but the following part is not working:

response = client.analyze_syntax(request = {'document': document, 'encoding_type': encoding_type})
# Loop through tokens returned from the API
for token in response.tokens:
# Get the text content of this token. Usually a word or punctuation.
text = token.text
print(u"Token text: {}".format(text.content))
print(
u"Location of this token in overall document: {}".format(text.begin_offset)
)
# Get the part of speech information for this token.
# Parts of spech are as defined in:
# http://www.lrec-conf.org/proceedings/lrec2012/pdf/274_Paper.pdf
part_of_speech = token.part_of_speech
# Get the tag, e.g. NOUN, ADJ for Adjective, et al.
print(
u"Part of Speech tag: {}".format(
language_v1.PartOfSpeech.Tag(part_of_speech.tag).name
)
)

it returns an error: AttributeError: module 'google.cloud.language_v1' has no attribute 'PartOfSpeech'

What should I do to fix this?
Thank you.

classify_text samples are not yet compatible with Python 3.10 due to numpy

https://github.com/googleapis/python-language/search?q=numpy

https://source.cloud.google.com/results/invocations/e21f0eb6-962c-4f49-a6bb-615a8dd2b831/targets/cloud-devrel%2Fclient-libraries%2Fpython%2Fgoogleapis%2Fpython-language%2Fsamples%2Fpython3.10%2Fpresubmit/log

  ----------------------------------------
  ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly
nox > Session py-3.10 failed.

How to use the outputs

How exactly do I use outputs of class 'google.cloud.language_v1.types.language_service.AnalyzeEntitiesResponse'? They are not json serializable or scriptable, but printing them looks very much like jsons. What other formats can I convert them to and how?

KeyError in LanguageServiceClient with 'grpc_asyncio' transport

Hi,

When language_v1.LanguageServiceClient is used with grpc_asyncio transport, a KeyError is raised on any language service method call (e.g. annotate_text).

After investigation, I've found that the issue is in LanguageServiceGrpcAsyncIOTransport.__init__. Stubs are set to empty dictionary after super().__init__ which causes KeyError on service method calls.

Environment details

  • OS type and version: macOS Catalina v10.15.6
  • Python version: 3.8.5
  • pip version: 20.3
  • google-cloud-language version: 2.0.0

Steps to reproduce

  1. Create a language_v1.LanguageServiceClient client with transport="grpc_asyncio".
  2. Call any service method

Code example

from google.cloud import language_v1

client = language_v1.LanguageServiceClient(transport="grpc_asyncio")

document = language_v1.Document(
    content="Example content.",
    language="en",
    type_=language_v1.Document.Type.PLAIN_TEXT,
)

response = client.annotate_text(
    request={
        "document": document,
        "features": {"extract_document_sentiment": True, "classify_text": True},
        "encoding_type": language_v1.EncodingType.UTF8,
    }
)

Stack trace

Traceback (most recent call last):
  File "example.py", line 11, in <module>
    response = client.annotate_text(
  File "/Users/nemanja/.pyenv/versions/example/lib/python3.8/site-packages/google/cloud/language_v1/services/language_service/client.py", line 725, in annotate_text
    rpc = self._transport._wrapped_methods[self._transport.annotate_text]
KeyError: <grpc.aio._channel.UnaryUnaryMultiCallable object at 0x10abc6d90>
Error in sys.excepthook:

Original exception was:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.