简体   繁体   English

如何在谷歌云存储中获取 GS_SECRET_ACCESS_KEY 和 GS_ACCESS_KEY_ID

[英]How to get GS_SECRET_ACCESS_KEY and GS_ACCESS_KEY_ID in google cloud storage

I try to read data from public google cloud storage ( https://console.cloud.google.com/storage/browser/gcp-public-data-landsat ) with Landsat images.我尝试使用 Landsat 图像从公共谷歌云存储( https://console.cloud.google.com/storage/browser/gcp-public-data-landsat )读取数据。

I use for it Python3 with GDAL.我将 Python3 与 GDAL 一起使用。 But I have an error但我有一个错误

ERROR 15: GS_SECRET_ACCESS_KEY+GS_ACCESS_KEY_ID, GS_OAUTH2_REFRESH_TOKEN or GOOGLE_APPLICATION_CREDENTIALS or GS_OAUTH2_PRIVATE_KEY+GS_OAUTH2_CLIENT_EMAIL configuration options and /home/qwerty/.boto not defined

How can I get GS_SECRET_ACCESS_KEY and GS_ACCESS_KEY_ID?如何获取 GS_SECRET_ACCESS_KEY 和 GS_ACCESS_KEY_ID?

gs_access_key_id and gs_secret_access_key can be generated by gs_access_key_idgs_secret_access_key可以由

1.navigating to your Google Cloud Storage console and clicking on Settings . 1.导航到您的 Google Cloud Storage 控制台并单击Settings

2.on the Settings page, navigate to the Interoperability tab. 2. 在Settings页面上,导航到Interoperability选项卡。

3.on this page you can now choose a service account and click Create a new key to generate an access key and a matching secret. 3.在此页面上,您现在可以选择一个服务帐户并单击Create a new key以生成访问密钥和匹配的密钥。

Output:输出:

New service account HMAC key
service-account@project.iam.gserviceaccount.com
Access key  
xxxxxxxxxxxxxxxxxxx
Secret  
xxxxxxxxxxxxxxxxxxx
Copy this key's secret if you'll need it in the future. Once you close this dialog, the secret can't be recovered.

An alternative authentication approach to reading and optionally writing GeoTIF in GCS.在 GCS 中读取和选择性写入 GeoTIF 的另一种身份验证方法。

In CGP Console在 CGP 控制台中

  • Create a Service Account and download a JSON keyfile.创建服务帐户并下载 JSON 密钥文件。 Keep it safe.保持安全。
  • On the Storage Bucket browser, Permission tab, give the new Service Account Roles for:在存储桶浏览器的权限选项卡上,为以下各项提供新的服务帐户角色:
    • Storage Legacy Bucket Owner and Storage Legacy Bucket Owner 和
    • Storage Legacy Bucket Reader Storage Legacy Bucket Reader
    • path_to_credentials points to your key file path_to_credentials 指向您的密钥文件
    GEOTIF_PATH = "/vsigs/<my-bucket>/<objectname>"

    with rasterio.Env(GOOGLE_APPLICATION_CREDENTIALS=path_to_credentials):
        with rasterio.open('{}'.format(GEOTIF_PATH)) as src:
            print(src.width, src.height)
            profile = src.profile
            print(profile)

Following up on intotecho answer, I use this snippet to automatically set the application default credentials globally跟进 intotecho 答案,我使用此代码段自动全局设置应用程序默认凭据

import os

import rasterio
from google.auth import _cloud_sdk, environment_vars


def get_application_default_credentials_path() -> str:
    explicit_file = os.environ.get(environment_vars.CREDENTIALS)
    if explicit_file:
        return explicit_file
    # check if application default credentials exist.
    credentials_filename = _cloud_sdk.get_application_default_credentials_path()
    if credentials_filename:
        return credentials_filename
    return None


def set_application_default_credentials():
    app_default_creds_path = get_application_default_credentials_path()
    if app_default_creds_path:
        rasterio.Env(GOOGLE_APPLICATION_CREDENTIALS=app_default_creds_path)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取 ECR_AWS_ACCESS_KEY 和 ECR_AWS_SECRET_ACCESS_KEY - How to get ECR_AWS_ACCESS_KEY and ECR_AWS_SECRET_ACCESS_KEY 无法从环境变量(AWS_ACCESS_KEY_ID(或 AWS_ACCESS_KEY)和 AWS_SECRET_KEY(或 AWS_SECRET_ACCESS_KEY))加载 AWS 凭证 - Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)) 是否可以从已被授权访问 GS 存储桶的谷歌帐户授权谷歌服务帐户? - is it possible to authorize google service account from google account that is already authorized to have access on GS buckets? 服务帐户没有对 Google Cloud Storage 的 storage.objects.get 访问权限 - service account does not have storage.objects.get access for Google Cloud Storage 在 env 中找到部分凭据,缺少:AWS_SECRET_ACCESS_KEY - Partial credentials found in env, missing: AWS_SECRET_ACCESS_KEY 如何使用 pip 下载 python package 到具有公共访问权限的谷歌云存储桶中并从那里安装 - How to download a python package using pip into google Cloud Storage bucket with public access and to install from there 在谷歌云存储中访问 Spacy 的训练模型/文件夹 - Access Spacy's trained model/folder in google cloud storage 在 Github 上的开源项目的 travis.yml 文件中公开 s3 秘密访问密钥是否存在安全风险? - Is exposing a s3 secret access key in travis.yml file on an opensource project on Github a security risk? 无法导入 gs://bucket_name/Cloud.sql - Failed to import gs://bucket_name/Cloud.sql Nuxt3 和 Firebase 云 Function 托管:如何访问私钥 in.env 文件? - Nuxt3 and Firebase Cloud Function Hosting: How to access private key in .env file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM