[英]IBM Cloud Object Storage Connection issue Watson studio Python notebook
I have been trying to get my Python notebook in Watson Studio to connect to and retrieve data from my cloud storage for hours and read many tutorials but no idea why it is not working, code below:我一直在尝试让我的 Python 笔记本在 Watson Studio 中连接到我的云存储并从我的云存储中检索数据几个小时,并阅读了许多教程,但不知道为什么它不起作用,代码如下:
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))
this produces the error: CredentialRetrievalError: Error when retrieving credentials from https://iam.bluemix.net/oidc/token : HttpCode(400) - Retrieval of tokens from server failed.这会产生错误:CredentialRetrievalError:从https://iam.bluemix.net/oidc/token检索凭据时出错:HttpCode(400) - 从服务器检索令牌失败。
same result if I use " https://iam.cloud.ibm.com/identity/token " for the ibm_auth_endpoint如果我对 ibm_auth_endpoint 使用“ https://iam.cloud.ibm.com/identity/token ”,则结果相同
I've also tried a separate connection with HMAC credentials as well, but can't find any tutorials that show you how to incorporate those either...我也尝试过与 HMAC 凭据的单独连接,但找不到任何教程来展示如何合并这些凭据......
Please help!请帮忙!
Thanks谢谢
This can be caused due to the use of invalid apikey.这可能是由于使用了无效的 apikey 造成的。 To get an apikey value, go to the 'Service credentials' menu of your storage instance and then click on "View credentials" of the "WDP-Project-Management-..." and see the value in the 'apikey' field.要获取 apikey 值,go 到存储实例的“服务凭据”菜单,然后单击“WDP-项目管理-...”的“查看凭据”并查看“apikey”字段中的值。
This issue does not seem to be caused by invalid endpoint_url, bu anyway, to get the endpoint_url, go to Buckets > 'your bucket' > Configuration, and then choose an endpoint according to you needs (Private/Public/Direct).这个问题好像不是endpoint_url无效引起的,反正要获取endpoint_url,go到Buckets > 'your bucket' > Configuration,然后根据需要选择一个endpoint(Private/Public/Direct)。 When filling the field, use "https://".填写字段时,请使用“https://”。
See below a code snippet to get data from a cvs file directly:请参阅下面的代码片段以直接从 cvs 文件中获取数据:
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'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.