1
votes

My problem is that I can’t add a file to my google cloud storage bucket

def upload():
    from flask import request
    """Process the uploaded file and upload it to Google Cloud Storage."""
    uploaded_file = request.files.get('file')

    if not uploaded_file:
        return 'No file uploaded.', 400

    # Create a Cloud Storage client.
    credentials = compute_engine.Credentials()
    gcs = storage.Client(credentials=credentials, project="ISL-Creative")
    # gcs = storage.Client()
    # Get the bucket that the file will be uploaded to.
    bucket = gcs.get_bucket('label_creative')
    # Create a new blob and upload the file's content.
    blob = bucket.blob(uploaded_file.filename)
    blob.upload_from_string(
        uploaded_file.read(),
        content_type=uploaded_file.content_type
    )

    # The public URL can be used to directly access the uploaded file via HTTP.
    return 'ok'

google.auth.exceptions.RefreshError: HTTPConnectionPool(host='metadata.google.internal', port=80): Max retries exceeded with url: /computeMetadata/v1/instance/service-accounts/default/?recursive=true (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

1

1 Answers

1
votes

The error shows that your process isn't able to find metadata.google.internal. This is probably either:

  1. You aren't running on Google Compute Engine. compute_engine.Credentials() is only intended when running on GCE. Use different credentials on other systems. (in fact on GCE and GAE you don't need to specify credentials at all - default credentials are automatically used)

  2. You have a DNS Issue resolving metadata.google.internal. Make sure metadata.google.internal resolves to 169.254.169.254.