RetryError: 使用 Gcloud 调用 functools.partial 时超出了 600.0s 的截止日期

Sha*_* Wu 5 python python-3.x sentiment-analysis gcloud

我是 python 的初学者,正在尝试应用 Gcloud 情绪分析来分析一些句子。python代码由官方提供:https : //cloud.google.com/natural-language/docs/analyzing-sentiment

错误如下:

RetryError: 调用 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')]),最后一个异常:503 通道处于状态 TRANSIENT_FAILURE

我尝试了很多方法(例如禁用防火墙,切换到其他笔记本电脑/wifi)来解决但都失败了。我确定环境变量是使用应用程序默认凭据设置的,并且 API 已通过身份验证。

你有什么想法吗?非常感谢!

编码环境:

蟒蛇 3.6

赢10

来自 CMD pip 列表的 python 包——

gcloud (0.18.3),

谷歌 API 核心(1.7.0),

谷歌云语言 (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)
Run Code Online (Sandbox Code Playgroud)