GenAI-Showcase icon indicating copy to clipboard operation
GenAI-Showcase copied to clipboard

Issue with uploading image to gcs

Open JonoSuave opened this issue 6 months ago • 1 comments

I keep running into the following error: RefreshError Traceback (most recent call last) in <cell line: 0>() 10 gcs_key = f"multimodal-rag/{n+1}.png" 11 # Upload the image bytes to GCS ---> 12 upload_image_to_gcs(gcs_key, img_bytes) 13 # Extract some image metadata 14 temp["image"] = img_bytes

16 frames /usr/local/lib/python3.11/dist-packages/google/auth/compute_engine/credentials.py in refresh(self, request) 130 except exceptions.TransportError as caught_exc: 131 new_exc = exceptions.RefreshError(caught_exc) --> 132 raise new_exc from caught_exc 133 134 @property

RefreshError: ("Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Engine metadata service. Status: 404 Response:\nb''", <google.auth.transport.requests._Response object at 0x7b5c79273010>)

I tried to resolve by setting up a service key under a new project and ran the following:

from google.colab import files
uploaded = files.upload()  # Upload your JSON key file

import os
from google.oauth2 import service_account
from google.cloud import storage

# Replace with your actual file name
SERVICE_ACCOUNT_FILE = "your-key-file.json"

credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE
)

# Now initialize the GCS client with credentials
gcs_client = storage.Client(project=GCS_PROJECT)
gcs_bucket = gcs_client.bucket(GCS_BUCKET)

Still get the same error

Image

JonoSuave avatar Apr 08 '25 04:04 JonoSuave