Reputation: 21
I'm getting a Unexpected keyword argument 'ibm_api_key_id' error argument when using ibm-cos-sdk on python 3.6.2.
I've installed the library in a clean virtual enviroment using these steps:
virtualenv --python=python3.5 boto-test
source boto-test/bin/activate
pip install ibm-cos-sdk
Then, I've tried to run the example from here:
import boto3
import json
import requests
import random
from botocore.client import Config
from pprint import pprint
with open('./credentials.json') as data_file:
credentials = json.load(data_file)
print("Service credential:")
print(json.dumps(credentials, indent=2))
print("")
print("Connecting to COS...")
# Rquest detailed enpoint list
endpoints = requests.get(credentials.get('endpoints')).json()
#import pdb; pdb.set_trace()
# Obtain iam and cos host from the the detailed endpoints
iam_host = (endpoints['identity-endpoints']['iam-token'])
cos_host = (endpoints['service-endpoints']['cross-region']['us']['public']['us-geo'])
api_key = credentials.get('apikey')
service_instance_id = credentials.get('resource_instance_id')
# Constrict auth and cos endpoint
auth_endpoint = "https://" + iam_host + "/oidc/token"
service_endpoint = "https://" + cos_host
print("Creating client...")
# Get bucket list
cos = boto3.client('s3',
ibm_api_key_id=api_key,
ibm_service_instance_id=service_instance_id,
ibm_auth_endpoint=auth_endpoint,
config=Config(signature_version='oauth'),
endpoint_url=service_endpoint)
# Call S3 to list current buckets
response = cos.list_buckets()
# Get a list of all bucket names from the response
buckets = [bucket['Name'] for bucket in response['Buckets']]
# Print out the bucket list
print("Current Bucket List:")
print(json.dumps(buckets, indent=2))
print("---")
result = [bucket for bucket in buckets if 'cos-bucket-sample-' in bucket]
print("Creating a new bucket and uploading an object...")
if len(result) == 0 :
bucket_name = 'cos-bucket-sample-' + str(random.randint(100,99999999));
# Create a bucket
cos.create_bucket(Bucket=bucket_name)
# Upload a file
cos.upload_file('./example.py', bucket_name, 'example-object')
# Call S3 to list current buckets
response = cos.list_buckets()
# Get a list of all bucket names from the response
buckets = [bucket['Name'] for bucket in response['Buckets']]
# Print out the bucket list
print("New Bucket List:")
print(json.dumps(buckets, indent=2))
print("---")
else :
bucket_name = result[0];
# Call S3 to list current objects
response = cos.list_objects(Bucket=bucket_name)
# Get a list of all object names from the response
objects = [object['Key'] for object in response['Contents']]
# Print out the object list
print("Objects in %s:" % bucket_name)
print(json.dumps(objects, indent=2))
But when running, I get the following output:
Traceback (most recent call last): File "boto3test.py", line 1, in import boto3 File "/home/giovanni/Downloads/boto-test/lib/python3.5/site-packages/boto3/init.py", line 16, in from boto3.session import Session File "/home/giovanni/Downloads/boto-test/lib/python3.5/site-packages/boto3/session.py", line 27, in import botocore.session File "/home/giovanni/Downloads/boto-test/lib/python3.5/site-packages/botocore/session.py", line 37, in import botocore.credentials File "/home/giovanni/Downloads/boto-test/lib/python3.5/site-packages/botocore/credentials.py", line 27, in import httplib ImportError: No module named 'httplib'
Where am I doing something wrong? Shoud I install botocore in my virtualenv?
Upvotes: 1
Views: 708
Reputation: 21
I have found the problem: IBM's library ibm-cos-sdk-python-core, is their own version of the botocore library, however, on credentials.py from their repo, there is a reference to a library that's been renamed on Python 3 (httplib -> http.client).
So my fix was to replace line 27 of credentials.py on my local installation directory from:
import httplib
To:
import http.client as httplib
There was an open issue on the case (#1), however, I didn't saw because the repos had no connection to each other and I'm still learning how IBM's libraries work.
Upvotes: 1
Reputation: 1796
edit botocore/credentials.py and change import httplib to import http.client as httplib
Upvotes: 2