Exception has occurred: PermissionDenied 403 The caller does not have permission

Code:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "youtubegenerator-398520-dcb847f989be.json"
operation = client.long_running_recognize(config=config, audio=audio)

Error:

Exception has occurred: PermissionDenied
403 The caller does not have permission
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.PERMISSION_DENIED
    details = "The caller does not have permission"
    debug_error_string = "UNKNOWN:Error received from peer ipv4:172.217.13.202:443 {grpc_message:"The caller does not have permission", grpc_status:7, created_time:"2023-09-20T02:32:08.7757374+00:00"}"
>

The above exception was the direct cause of the following exception:

  File "C:\Users\user\Documents\YOUTUBE_VIDEO_GENERATOR\AutomatedYoutube.py", line 88, in <module>
    operation = client.long_running_recognize(config=config, audio=audio)
google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission

Trying to use the Cloud Speech-to-Text API. The json file is the service account on the Cloud Speech-to-Text API.

I know I'm communicating with it because I'm seeing this:

enter image description here

What might I be doing wrong?

Upvotes: 0

Views: 1140

Answers (2)

Srividya
Srividya

Reputation: 2323

The first step in resolving permission errors is to check your IAM permissions. IAM is a Google Cloud service that allows you to manage access to resources in your Cloud project. To access the Text-to-Speech API, you must have the necessary IAM roles.The roles you need depend on the level of access you require.

You now must link one or more service accounts to the Speech-to-Text API. Go to the Credentials tab, create credentials and choose Service Account from the drop down. Set the service account role as project owner and save the JSON private key file to your Google Drive. If you do not have any service accounts associated with this project, create one by following the instructions in the creating a new service account section.

Note: Make sure that you have access to a downloaded JSON key associated with the service account you'd like to use to authenticate with Speech-to-Text. If your service account has an existing key but you can't locate the downloaded .json file, you will need to create a new key for that service account and download its .json file. For instructions on how to create a new key on an existing service account, Refer to the creating a JSON key section.

Since you already have a service account and its JSON key and have set your authentication environment variable but getting the permission denied error and your code says you are using python here, you need to import the os module and set the environment variable using the code snippet below:

import os 

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = ‘$Home/.config/gcloud/application_default_credentials.json’

This will provide the location of the file. Also enable the Automl API for the project here.

Upvotes: 1

MrThompson
MrThompson

Reputation: 156

As redundant it might seems its usually a permission error.

Are you doing the execution from your local? If so you could check if your account has permissions over the SA that you have in the key, youtubegenerator-398520-dcb847f989be.json

And then you should set the app default credentials as stated here https://cloud.google.com/docs/authentication/provide-credentials-adc

Another, is the SA that you are using has permissions for execute and interact with the APIs you are mentioning?

Upvotes: 1

Related Questions