账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Google Cloud Client,报google.api_core.exceptions.Forbidden: 403错误
    36
    0

    来自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'}]
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部