question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v3: translateText fails after getSupportedLanguages using ADC

See original GitHub issue

Environment details

  • OS: macOS
  • Node.js version: 14.12.0
  • npm version: 6.14.8
  • @google-cloud/translate version: 6.0.3

Steps to reproduce

  1. Login with ADC: gcloud auth application-default login
  2. Install @google-cloud/translate with npm or yarn
  3. Run the below script: node script.js
  4. Check the output (also attached mine below)
  5. Notice that the first call works.translateText succeeds, but when calling fails.getSupportedLanguages and then fails.translateText it fails.
const { TranslationServiceClient } = require('@google-cloud/translate')

async function test() {
   const translateOpts = {
      contents: ['Hello'],
      targetLanguageCode: 'fr',
   }

   try {
      const works = new TranslationServiceClient()
      const parent = `projects/${await works.getProjectId()}`
      const [translation] = await works.translateText({
         parent,
         ...translateOpts,
      })
      console.info('[works] Translation succeeded:', translation)
   } catch (ex) {
      console.error('[works] Translation failed:', ex.message || ex)
   }

   try {
      const fails = new TranslationServiceClient()
      const parent = `projects/${await fails.getProjectId()}`
      const [langs] = await fails.getSupportedLanguages({ parent })
      console.info('[fails] Fetched supported languages:', langs.languages.length)
      const [translation] = await fails.translateText({
         parent,
         ...translateOpts,
      })
      console.info('[fails] Translation succeeded:', translation)
   } catch (ex) {
      console.error('[fails] Translation failed:', ex.message || ex)
   }
}

test()

Output for me:

$ node translate-repo.js
[works] Translation succeeded: {
  translations: [
    {
      translatedText: 'Bonjour',
      model: '',
      glossaryConfig: null,
      detectedLanguageCode: 'en'
    }
  ],
  glossaryTranslations: []
}
[fails] Fetched supported languages: 111
[fails] Translation failed: 7 PERMISSION_DENIED: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the translate.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rhodgkinscommented, Mar 3, 2021

🤷‍♂️ not sure then I’m afraid, can’t reproduce with 6.1.0 anyway so maybe it was fixed in a dependency down the line… Thanks for looking into it anyway!

1reaction
rhodgkinscommented, Mar 2, 2021

I’ll try reproducing again tomorrow, but have you tried that node version?

May i ask why are you using two different instances of translateServiceClient?

To reproduce the issue. Otherwise calling translateText would cause things to work. In production, just the second (failing) case is being used.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Package google.cloud.translation.v3
This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call. Authorization Scopes. Requires ...
Read more >
Understanding and minimising ADC conversion errors
1 INTRODUCTION. The purpose of this document is to explain the different ADC errors and the techniques that application developers can use to...
Read more >
c# - Google.Cloud.Translate.V3, error GRPC Failed to pick ...
we are developing a service that uses translation through Google and currently facing the following issue: translation through Google.Cloud.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found