首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >谷歌云自然语言API error:google.auth.exceptions.DefaultCredentialsError:无法自动确定凭据

谷歌云自然语言API error:google.auth.exceptions.DefaultCredentialsError:无法自动确定凭据
EN

Stack Overflow用户
提问于 2018-06-06 18:11:54
回答 2查看 1K关注 0票数 0

我从这个 使用了谷歌云的自然语言应用编程接口

和我在powershell中使用以下命令:

$env:GOOGLE_APPLICATION_CREDENTIALS="D:\analyze_sentiment\MyFirstProject-bbe4f7bccb98.json“

然后在cmd:中使用以下命令:

set GOOGLE_APPLICATION_CREDENTIALS=D:\analyze_sentiment\MyFirstProject-bbe4f7bccb98.json

但是当我使用代码时:

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))

错误消息显示:

raise exceptions.DefaultCredentialsError(_HELP_MESSAGE) google.auth.exceptions.DefaultCredentialsError:无法自动确定凭据。请设置GOOGLE_APPLICATION_CREDENTIALS或显式创建凭据,然后重新运行应用程序。详情请参考https://developers.google.com/accounts/docs/application-default-credentials

为什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-11 08:01:11

我知道错误的原因,我必须使用命令模式来运行代码,请不要运行代码与pycharm或其他IDE.And设置此link接口“启用”。

然后错误就消失了。

票数 0
EN

Stack Overflow用户

发布于 2018-06-07 20:24:58

我认为你必须在你的本地机器上也设置GOOGLE_APPLICATION_CREDENTIALS。下载Google Cloud Shell并在其中设置凭据

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50717812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档