Google-cloud-python: Unsuccessful authentication without errors/warnings

Created on 13 Mar 2017  路  21Comments  路  Source: googleapis/google-cloud-python

At first the authentication worked fine and I could see the API requests in the dashboard. But at some point the requests were not showing up anymore in the dashboard API overview.

I created a service account and stored the json file locally. Then I set the environment variable GCLOUD_PROJECT to the project ID and GOOGLE_APPLICATION_CREDENTIALS to the path of the json file.

from google.cloud import speech
client = speech.Client()
print(client._credentials.service_account_email)

Prints the correct service account email.

import io
with io.open(audio_file, 'rb') as f:
    audio = client.sample(f.read(), source_uri=None, sample_rate=48000, encoding=speech.encoding.Encoding.FLAC)
alternatives = audio.sync_recognize(language_code='de-DE')

The resulting transcript is correct, but nothing happens on the dashboard at
https://console.cloud.google.com/apis/api/speech.googleapis.com/overview?project=[project-ID]

I also tried to initialize the client with the function speech.Client.from_service_account_json and to authenticate by installing the Google Cloud SDK and gcloud auth application-default login, but without success.

The error count (Fehler) is increasing here but I don't know how to get additional information.

  • Windows 7
  • conda environment
  • python 3.5.2
  • google-cloud-speech 0.23.0
auth backend speech p2

Most helpful comment

It's None at first because the credentials have yet to be refreshed. It should be the time of execution plus one hour after because it refreshed during the execution.

All 21 comments

@elcombato thanks for reporting!

The resulting transcript is correct, but nothing happens on the dashboard...

That is pretty strange, because if you're getting results and a 200 response then it should be counting the requests on the dashboard.

Does the request count on the dashboard go up a few hours later?

@daspecster No it won't show up. The last activity is more than a week old and I used the API daily in the last week.

How can I evaluate that the client is correctly authenticated, to eliminate the possibility of an user error by me?

You can check the actual authenticated account and project via client._credentials.__dict__ and client._project

@dhermes With my code from above the object client has no attribute _project.

In client._credentials.__dict__ everything looks fine. Is it expected behavior, that client._credentials.expiry is None after the initialization of speech.Client() and after running client.sample() and sync_recognize() the variable client._credentials.expiry is set to the time of execution?

It's None at first because the credentials have yet to be refreshed. It should be the time of execution plus one hour after because it refreshed during the execution.

There is no plus one hour:

from google.cloud import speech
from datetime import datetime

client = speech.Client()

with open("speech.flac", 'rb') as f:
    audio = f.read()
sample = client.sample(audio, source_uri=None, sample_rate=48000, encoding='FLAC')
a = sample.sync_recognize()

print(client._credentials.expiry)
print(client._credentials.expired)
print(datetime.now())

# 2017-03-13 17:24:59.845493
# False
# 2017-03-13 17:25:40.128734

@elcombato what's datetime.utcnow()?

ok yea, that is 2017-03-13 16:32:29.200383. So expiry is in utc.

Any thoughts on the missing _project attribute?

Not sure, you can try executing credentials, project = google.auth.default() and see what it says. You can also explicitly pass the project into the Client constructor.

Both the credentials and project are correct.

@daspecster It seems there is no project used in the Speech API. Can you confirm? @elcombato Since that's the case, it seems the relevant project dashboard would be the project that owns the service account credentials.

@dhermes looking now.

Yeah, it's using google.cloud.core.client.Client instead of ClientWithProject.

The Speech authentication docs mention projects but kind of in a general way. Also, it used to be an API key based API so maybe that has something to do with it?

@lukesneeringer is there someone we can ask about how Speech supports project IDs?

Maybe @gguuss knows?

re: project IDs on Speech API projects, I have a few contacts from the team but I'm not sure they're on GH.

@gguuss Any update on this?

The project ID is only used when the content is a private GCS file.

Thanks @gguuss. That puts us more or less back where we started; project is not the culprit.
To be honest, I have no idea why the dashboard does not reflect anything, and that is a backend issue... :-/

The API calls are now showing up on my dashboard after updating to 0.24

How incredibly bizarre.
Closing this issue. Feel free to reopen if the problem pops back up.

Was this page helpful?
0 / 5 - 0 ratings