0
votes

While running code in IDLE, it shows nothing.

from ibm_botocore.client import Config

import ibm_boto3

def upload_file(credentials,local_file_name,key):

cos = ibm_boto3.client(service_name='s3', ibm_api_key_id=credentials['got from service credential desciption'],

ibm_service_instance_id=credentials['got from service credential description'],

ibm_auth_endpoint=credentials['s3.eu-gb.cloud-object-storage.appdomain.cloud'],//as my region is London

config=Config(signature_version='oauth'),

endpoint_url=credentials['https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints'])

try:

res=cos.upload_file(Filename='D:\ibm-cloud\get-started-python\abc.txt', 

Bucket=credentials['cloud-college-bucket0'],Key=key)

except Exception as e:

print(Exception, e)

else:

print('File Uploaded')
1

1 Answers

2
votes

You're not providing a valid endpoint_url. The value you're pulling out of the credentials will provide a list of valid endpoints, but isn't valid itself. Learn more in the docs.

Edit: Ah, I see. You've put the correct endpoint in the wrong place. Just take what you have in ibm_auth_endpoint and use it for endpoint_url. You can actually omit the authorization endpoint line entirely (the SDK will default to the correct value), or you can use https://iam.cloud.ibm.com/identity/token.

Try this:

import ibm_boto3
from ibm_botocore.client import Config

cos = ibm_boto3.client(service_name='s3',
                       ibm_api_key_id='<some API key>',
                       ibm_service_instance_id='<got from service credential description>',
                       config=Config(signature_version='oauth'),
                       endpoint_url='https://s3.eu-gb.cloud-object-storage.appdomain.cloud')

try:
    res = cos.upload_file('D:\ibm-cloud\get-started-python\abc.txt',
                      'cloud-college-bucket0', 'some-key')
except Exception as e:
    print(Exception, e)
else:
    print('File Uploaded')