API调用无响应

时间:2019-05-27 08:35:59

标签: python api google-cloud-platform

我尝试使用Google云API提供的某些服务,并按照该教程进行操作,并且在安装SDK和授权文件后,我开始调用。但是无论哪种方式,程序在执行后都会卡住,然后等待,没有结果或任何错误。尝试使用Java和python是同一回事。您现在如何解决此问题

我在中国使用它,但是我已经使用了全球代理模型。否则我将无法下载某些python软件包

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

text = 'President Kennedy spoke at the White House.'

client = language.LanguageServiceClient()

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

# Instantiates a plain text document.
document = types.Document(
    content=text,
    type=enums.Document.Type.PLAIN_TEXT)

# Detects syntax in the document. You can also analyze HTML with:
#   document.type == enums.Document.Type.HTML
tokens = client.analyze_syntax(document).tokens

for token in tokens:
    part_of_speech_tag = enums.PartOfSpeech.Tag(token.part_of_speech.tag)
    print(u'{}: {}'.format(part_of_speech_tag.name,
                           token.text.content))

无法获得有用的信息或错误消息,并且程序没有中断,等待返回结果

1 个答案:

答案 0 :(得分:0)

中国禁止在中国内部访问许多/大多数Google服务(端点)。如果您在家中进行此操作,那几乎可以肯定。

您最好的选择是注册阿里云,然后使用虚拟机访问Google服务。阿里巴巴的网络通常会“通过防火墙”。