0

The docs says that I can get the keys by this request:

POST https://iam.googleapis.com/v1/projects/PROJECT-ID/serviceAccounts/[email protected]/keys

I created a service account. For the example lets say:

SA-NAME = xxx
PROJECT-ID = yy-zz

When i do (Python)

import requests
url = 'https://iam.googleapis.com/v1/projects/yy-zz/serviceAccounts/[email protected]/keys'
try:
    g = requests.post(url, verify=True)
except requests.exceptions.HTTPError as err:
    print err
    sys.exit(1)
print g

I get:

<Response [403]>

What am I doing wrong?

1 Answer 1

1

You need to authenticate using OAuth2 to be able to use the service. The 403 error you're receiving is expected because your not authenticating before trying to use the service.

See the following links for some information on authenticating via these methods: https://developers.google.com/identity/protocols/OAuth2

Authenticating to the service may look like the following:

from google.oauth2 import service_account

SCOPES = ['https://www.googleapis.com/auth/sqlservice.admin']
SERVICE_ACCOUNT_FILE = '/path/to/service.json'

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)
Sign up to request clarification or add additional context in comments.

10 Comments

But I don't have a file... File means it's constant isn't it? Shouldn't I get auth for every API call?
Yep that's correct. In the method I've used above, you would already have a service account setup and SERVICE_ACCOUNT_FILE would be the path to the private key that was generated when you created the account.
Are you looking to use a dedicated service account to make API calls? Or are you looking to use your own account to make the call?
I have a service account setup from where do i get the Json? Also, What If I need to upload a file to google storage? What needs to change in the code?
I just want to upload Json file to storage and then process it with BigQuery. It's a process that will run from cronjob.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.