Google云视频智能API权限不足及tmp目录删除报错排查求助
Hey there, let's sort out your two issues clearly—first, let's talk about priority, then dive into each problem's root cause and fixes:
This is the critical issue you need to tackle first. The 403 error directly blocks your code from communicating with Google Cloud's Video Intelligence API—without resolving this, your person recognition functionality won't run at all. The rm error is just a minor cleanup warning that doesn't break core logic.
Root Cause of the 403 Error
Your authentication credentials (whether local gcloud auth or a service account key) lack the required access scopes to interact with the Video Intelligence API. Scopes define the specific permissions your code has when accessing Google Cloud services, and your current setup has overly restrictive scopes.
Fixes for the 403 Error
- If using local gcloud authentication:
Run these terminal commands to set your project and grant full cloud platform scopes (ideal for development testing):gcloud auth application-default set-quota-project YOUR_PROJECT_ID gcloud auth application-default login --scopes=https://www.googleapis.com/auth/cloud-platform - If using a service account key:
- Head to your Google Cloud Console, go to IAM & Admin > IAM.
- Locate your service account and assign it a role like
Video Intelligence ViewerorVideo Intelligence Editor—these roles include all necessary permissions for person recognition. - In your code, explicitly load the key with the correct scopes:
from google.oauth2 import service_account credentials = service_account.Credentials.from_service_account_file( '/path/to/your/service-account-key.json', scopes=['https://www.googleapis.com/auth/cloud-platform'], )
- Double-check your code's auth setup:
If you're usinggoogle.auth.default()to fetch credentials, make sure your runtime environment (local machine, cloud instance) has the proper scopes configured.
rm: cannot remove 'tmp': No such file or directory Error This is a trivial issue with your init() function's cleanup logic—it doesn't impact your core person recognition workflow.
Root Cause
Your init() function is attempting to delete a directory named tmp, but that directory doesn't exist when the function executes. The shell throws an error because there's nothing to remove.
Fixes
- If it's a bash command in your script:
Modify the delete line to check for the directory's existence first:if [ -d "tmp" ]; then rm -rf tmp; fi - If it's Python code handling cleanup:
Use Python's built-in file utilities to verify the directory exists before deletion:import os import shutil def init(): # Your other init logic here if os.path.exists('tmp'): shutil.rmtree('tmp') - Alternatively:
You can ignore this error if you don't mind the warning in your logs, but fixing it will clean up your output and eliminate unnecessary noise.
内容的提问来源于stack exchange,提问作者anna livingston

