google.auth.exceptions.RefreshError

时间:2019-04-10 14:33:06

标签: python google-cloud-platform google-cloud-storage

我的问题是我无法将文件添加到我的Google云存储桶中

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):URL超过了最大重试次数:/ computeMetadata / v1 / instance / service-accounts / default /?recursive = true(由于NewConnectionError(':导致无法建立新连接:[Errno 8]节点名或提供的服务名,或者未知'))

1 个答案:

答案 0 :(得分:0)

该错误表明您的进程无法找到metadata.google.internal。这可能是:

  1. 您没有在Google Compute Engine上运行。 compute_engine.Credentials()仅在GCE上运行时适用。在其他系统上使用不同的凭据。 (实际上,在GCE和GAE上,您根本不需要指定凭据-自动使用默认凭据)

  2. 您有一个DNS问题,解决了metadata.google.internal。确保metadata.google.internal解析为169.254.169.254。