我需要帮助...我无法从我在 Watson Studio 中创建的笔记本访问我使用 IBM Cloud 仪表板创建的 COS 中的存储桶。调用这个bucket3。
最初,我使用 IBM Watson“添加资产”从单个 f2.zip (csv) 文件创建了一个 bucket2,并且我能够访问 f2.zip。调用这个bucket2。
f2.zip 上传到 bucket2 - 后来发现它是在以前的 COS 存储上创建的;IE。在 IBM Cloud“cloud-object-storage-nl”上创建的资产。调用这个bucket1。我在 IBM Cloud 上有一个 Lite COS,名称 = 'cloud-object-storage-xx'。
我可以阅读 f2.zip,并且可以使用“文件 UI”按钮生成的凭据 (cred_b2_editor) 在 bucket2 中创建一个新的 f2.zip。
IBM Cloud 仪表板显示:
bucket1 us-geo Standard
bucket2 us-geo Standard
bucket3 us-east Standard
我正在使用Creating a new text file
Using Python ibm-cos-sdk 中的示例。
在 2 种情况下失败并显示“ClientError:调用 PutObject 操作时发生错误 (413):请求实体太大”:
- 当我从 IBM Cloud 生成的存储桶凭证中使用 endpoint_url = 'endpoints' 时)- ibm_api_key_id 无关紧要。
成功:当我使用 endpoint_url = 'endpoint_url' 形式时,Watson Studio 生成的 watson 凭证......无论 ibm_api_key_id(bucket2 或 bucket3)如何,都会写入 bucket2
代码:
# Point to generated credentials
credDict = dict(b2 = cred_b2_editor,
b3 = cred_b3_writer,
watson = cred_watson
)
bucketName = 'b3'
kwargs = dict(
ibm_api_key_id=credDict[bucketName]['ibm_api_key_id'],
ibm_service_instance_id=credDict[bucketName]['cred']['iam_serviceid_crn'], #COS_RESOURCE_CRN,
ibm_auth_endpoint=COS_AUTH_ENDPOINT,
config=Config(signature_version="oauth"),
endpoint_url=credDict[bucketName]['ep_private']
)
buckName = bucketDict[bucketName].split(':')[-1:][0]
print(buckName, kwargs['ibm_api_key_id'], kwargs['endpoint_url'])
cos = ibm_boto3.resource("s3", **kwargs)
#---> fix: bucketname needed to change with each bucket...
#---> fix: endpoint_url needs to point to private/public endpoint
cos.Object(buckName, csvBN.replace('.csv','.zip')).put(
Body=zbuf
)
凭据代码 - 以下所有内容均已生成
'''
Cloud Resource Name or 'bucket ID string'
The last field is the `bucketName`
'''
bucketDict = dict(b2 = 'crn:v1:bluemix:public:cloud-object-storage:global:a/<IDNum>:<serviceID-seperated>:bucket:bucket2',
b3 = 'crn:v1:bluemix:public:cloud-object-storage:global:a/<IDNum>:<serviceID-seperated>:bucket:bucket3'
)
# Bucket2 Editor credentials - created by IBM Watson automatically
cred_b2_editor = {
"apikey": "....",
"cos_hmac_keys": {
"access_key_id": "...",
"secret_access_key": "..."
},
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/<ServiceIDNum>:<COS_ID>::",
"iam_apikey_name": "auto-generated-apikey-<apikey_2>",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/<ServiceIDNum>::serviceid:ServiceId-<serviceID_2>",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/<ServiceIDNum>:<COS_ID>::"
}
## Bucket3 Create via IBM Cloud "New Credentials"
cred_b3_writer = {
"apikey": "4hEJq-slh28Atvq3XnekZ4YOl0yWiv4LbFigoPS3oiuL",
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/<ServiceIDNum>-<COS_ID>::",
"iam_apikey_name": "auto-generated-apikey-<apikey_3>",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/<ServiceIDNum>::serviceid:ServiceId-<ServiceID_3>",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/<ServiceIDNum>:<COS_ID>::"
}
# Created inside juptyer notebook 10/01 button
cred_b2_cos = dict(ibm_api_key_id=cred_b2['apikey'],
ibm_auth_endpoint="https://iam.ng.bluemix.net/oidc/token",
config=Config(signature_version='oauth'),
ep_private='https://s3-api.us-geo.objectstorage.service.networklayer.com',
ep_public = 'https://s3-api.us-geo.objectstorage.softlayer.net',
cred = cred_b2_editor
)
cred_b3_cos = dict(ibm_api_key_id=cred_b3['apikey'],
ibm_auth_endpoint="https://iam.ng.bluemix.net/oidc/token",
config=Config(signature_version='oauth'),
ep_private = 'https://s3.us-east.objectstorage.service.networklayer.com',
ep_public = 'https://s3.us-east.objectstorage.softlayer.net',
cred = cred_b3_writer
)