首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IBM Cloud Object Storage Connection问题Watson studio Python notebook

IBM Cloud Object Storage Connection问题Watson studio Python notebook
EN

Stack Overflow用户
提问于 2019-11-08 03:36:57
回答 1查看 650关注 0票数 4

几个小时以来,我一直在尝试让我的Python笔记本在Watson Studio中连接到我的云存储并从云存储中检索数据,并阅读了许多教程,但不知道为什么它不能工作,代码如下:

代码语言:javascript
复制
credentials = {
    'BUCKET': 'openai-data',
    'URL': 'https://s3.private.us-east.cloud-object-storage.appdomain.cloud',
    'SECRET_KEY': '',
    'API_KEY': '*********************', #this key has been *d out but the value is there in my code
    'RESOURCE_INSTANCE_ID': 'crn:v1:bluemix:public:cloud-object-storage:global:a/e448d36ef93f4d3ca55077db903d3461:51ce6e50-4e92-41d0-b002-5023e815cadc::',
    'FILE': 'test_Y_smallsample.h5',
    'ACCESS_KEY': ''
}


from ibm_botocore.client import Config
import ibm_boto3
cos = ibm_boto3.resource(service_name='s3',
    ibm_api_key_id=credentials['API_KEY'],
    ibm_service_instance_id=credentials['RESOURCE_INSTANCE_ID'],
    ibm_auth_endpoint='https://iam.bluemix.net/oidc/token',
    config=Config(signature_version='oauth'),
    endpoint_url=credentials['URL'])

files = cos.Bucket('openai-data').objects.all()
for file in files:
    print("Item: {0} ({1} bytes).".format(file.key, file.size))

这会产生错误: CredentialRetrievalError: Error when Retrieval from https://iam.bluemix.net/oidc/token:HttpCode(400) -从服务器检索令牌失败。

如果我对ibm_auth_endpoint使用"https://iam.cloud.ibm.com/identity/token“,结果是一样的

我也尝试过使用HMAC凭证进行单独的连接,但也找不到任何教程来向您展示如何将它们结合在一起……

请帮帮我!

谢谢

EN

回答 1

Stack Overflow用户

发布于 2019-11-23 09:34:37

这可能是由于使用了无效的apikey造成的。要获取apiKey值,请转到存储实例的“Service credentials”菜单,然后单击"WDP-Project-Management-...“的"View credentials”。并查看“apikey”字段中的值。

这个问题似乎不是由无效的endpoint_url引起的,但是无论如何,要获取endpoint_url,请转到Buckets > 'your bucket‘> Configuration,然后根据您的需要(私有/公共/直接)选择一个端点。填写该字段时,请使用"https://"“。

直接从cvs文件中获取数据的代码片段如下:

代码语言:javascript
复制
import pandas as pd 
import ibm_boto3 
from ibm_botocore.client import Config 
cos = ibm_boto3.client(service_name='s3',
    ibm_api_key_id='<apikey>', 
    ibm_auth_endpoint="https://iam.ng.bluemix.net/oidc/token",
    config=Config(signature_version='oauth'),
    endpoint_url="<endpoint>")
obj = cos.get_object(Bucket='<bucket_name>', Key='<csv_file>')
df = pd.read_csv(obj['Body'])
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58755809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档