Google Cloud Client,报google.api_core.exceptions.Forbidden: 403错误
来自Google Cloud Client Libraries官方文档:https://googlecloudplatform.g...
from google.cloud import translate
client = translate.Client()
client.translate(['Me llamo Jeff', 'My name is Jeff'],target_language='de')
代码执行结果:
C:\Python27\lib\site-packages\google\auth\_default.py:66: UserWarning: Your application has authenticated using end user
credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your app
lication continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled"
error. For more information about service accounts, see https://cloud.google.com/docs/authentication/.
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
Traceback (most recent call last):
File "C:\Code\Google\test\run.py", line 15, in <module>
target_language=target)
File "C:\Python27\lib\site-packages\google\cloud\translate_v2\client.py", line 233, in translate
method='POST', path='', data=data)
File "C:\Python27\lib\site-packages\google\cloud\_http.py", line 293, in api_request
raise exceptions.from_http_response(response)
google.api_core.exceptions.Forbidden: 403 POST https://translation.googleapis.com/language/translate/v2: Your applicatio
n has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported b
y the translate.googleapis.com. We recommend that most server applications use service accounts instead. For more inform
ation about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.
而如果在cmd下执行的话,可以正常执行
>>> from google.cloud import translate
>>> client = translate.Client()
>>> client.translate(['Me llamo Jeff', 'My name is Jeff'],target_language='de')
[{u'translatedText': u'Mein Name ist Jeff', 'input': 'Me llamo Jeff', u'detected
SourceLanguage': u'es'}, {u'translatedText': u'Mein Name ist Jeff', 'input': 'My
name is Jeff', u'detectedSourceLanguage': u'en'}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论