[英]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_id
和gs_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 控制台中
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.