RetryError: Deadline of 600.0s exceeded while calling functools.partial by using Gcloud

Viewed 1336

I'm a beginner to python and trying to apply Gcloud Sentiment Analysis to analyze some sentences. The python code is provided by official here: https://cloud.google.com/natural-language/docs/analyzing-sentiment

The error is as follows:

RetryError: Deadline of 600.0s exceeded while calling functools.partial(.error_remapped_callable at 0x0000020081C0EB70>, document { type: PLAIN_TEXT content: "yes i do!" } , metadata=[('x-goog-api-client', 'gl-python/3.6.5 grpc/1.17.1 gax/1.7.0 gapic/1.1.1')]), last exception: 503 channel is in state TRANSIENT_FAILURE

I've tried many ways (e.g. disable firewall, switch to other laptop / wifi) to solve but failed. I'm sure environment variable is set up using Application Default Credentials, and API is authenticated.

Could you have any ideas? Many thanks!

Coding environment:

Python 3.6

Win10

python package from CMD pip list --

gcloud (0.18.3),

google-api-core (1.7.0),

google-cloud-language (1.1.1)

from google.cloud import language_v1
from google.cloud.language_v1 import enums
import six


    def sample_analyze_sentiment(content):

    client = language_v1.LanguageServiceClient()

    # content = 'Your text to analyze, e.g. Hello, world!'

    if isinstance(content, six.binary_type):
        content = content.decode('utf-8')

    type_ = enums.Document.Type.PLAIN_TEXT
    document = {'type': type_, 'content': content}

    response = client.analyze_sentiment(document)
    sentiment = response.document_sentiment
    print('Score: {}'.format(sentiment.score))
    print('Magnitude: {}'.format(sentiment.magnitude))

text = 'yes i do!'
sample_analyze_sentiment(text)
0 Answers
Related