Unerwartetes Schlüsselwortargument „ibm_api_key_id“ bei Verwendung von ibm-cos-sdk?Python

Python-Programme
Anonymous
 Unerwartetes Schlüsselwortargument „ibm_api_key_id“ bei Verwendung von ibm-cos-sdk?

Post by Anonymous »

Ich erhalte das Fehlerargument „Unerwartetes Schlüsselwortargument „ibm_api_key_id“, wenn ich ibm-cos-sdk unter Python 3.6.2 verwende.
Ich habe die Bibliothek mit diesen Schritten in einer sauberen virtuellen Umgebung installiert:

Code: Select all

virtualenv --python=python3.5 boto-test
source boto-test/bin/activate
pip install ibm-cos-sdk
Dann habe ich versucht, das Beispiel von hier aus auszuführen:

Code: Select all

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))
Aber beim Ausführen erhalte ich die folgende Ausgabe:

Code: Select all

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'
Wo mache ich etwas falsch? Soll ich Botocore in meiner virtuellen Umgebung installieren?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post