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 togoogle-cloud-python.
Python Client for Natural Language API
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.
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.
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
Initialize document and content_categories_version as below.
Run the script with a text string
Code example
## Providing the code I'm using for testing the API call:importosfromgoogle.cloudimportlanguage_v1## Set Google API Keyos.environ.get("GOOGLE_APPLICATION_CREDENTAILS")
client=language_v1.LanguageServiceClient()
defcategorize(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)
forcategoryinresponse.categories:
result[category.name] =category.confidenceprint(result)
best_response=max(result, key=result.get)
lst=best_response.split(sep='/')
out_category=lst[-1]
returnout_categorytxt='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.
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.
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.
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 >
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)
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)
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.
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.
defsample_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, HTMLtype_=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/languageslanguage="en"document= {"content": text_content, "type": type_, "language": language}
# Available values: NONE, UTF8, UTF16, UTF32encoding_type=language_v1.EncodingType.UTF8response=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.
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
Send a Document to LanguageServiceClient -> analyze_sentiment
Include a Dutch string
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.
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.
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 >
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.
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?
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.
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.
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))
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)
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 >
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'
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'
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)
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)
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.
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.
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.
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
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."
}
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 >
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 >
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.
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'
----------------------------------------
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 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?
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
Create a language_v1.LanguageServiceClient client with transport="grpc_asyncio".
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: