mongodb-developer / mongodb-developer/GenAI-Showcase
Issue with uploading image to gcs
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.3k
- Forks
- 746
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 2
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the notebook cell that calls upload_image_to_gcs and reviewing the GCS client initialization shown in the issue. Reproduce the upload in Google Colab and compare the configured credentials with the client used by the upload path. Done means the image upload completes without the RefreshError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- google-cloud, jupyter-notebook, python
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100