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.

set correct project when using from_service_account_json

See original GitHub issue

When instantiating with bigquery.Client.from_service_account_json('...') the project field in the client should be set to the project_id defined in the service account JSON.

Right now it is still the one from env.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
andersgbcommented, Feb 12, 2017

I ran into this issue when attempting to switch from the more manual googleapiclient to this library.

Using googleapiclient:

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery

scopes = ['https://www.googleapis.com/auth/devstorage.full_control']
credentials = ServiceAccountCredentials.from_json_keyfile_name('service_acct_key.json', scopes)
# No need to specify project ID:
svc = discovery.build('storage', 'v1', credentials=credentials)
# svc.objects().insert() et al does not require project ID

Using google.cloud:

from google.cloud import storage

# this fails unless default project ID can be derived from env
client = storage.Client.from_service_account_json('service_acct_key.json')

As pointed out in this thread, if we manually specify the project argument to Client in the latter example it will work. Dunno how relevant this comparison is, but the difference in default behaviour took me a while to figure out.

1reaction
jgeewaxcommented, Jun 23, 2016

If the project ID isn’t in the JSON file, then they manually deleted it… I don’t think that’s a common thing…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create and manage service account keys - IAM - Google Cloud
In the Google Cloud console, go to the Service accounts page. · Select a project. · Click the email address of the service...
Read more >
gcloud auth activate-service-account from JSON to set current ...
I can see that, but my question is how to how to set the active project from that JSON file. I can't use...
Read more >
How to run gcloud command line using a service account
Create a service account with GCP console · Download the json key file · Create a role and assign proper required permissions to...
Read more >
Service Accounts | Google Earth Engine
Once you have a service account, click the menu for that account (more_vert), then Create key > JSON. Download the JSON key file....
Read more >
How to create a Google Cloud Service Account and download ...
In this video, I am going to show you how to create a Google Cloud Service account and download the Cloud Service client...
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