2017-10-16 13 views
1

Python 3.6.2でibm-cos-sdkを使用しているときに、予期しないキーワード引数 'ibm_api_key_id'が発生しました。私はこれらの手順を使用してクリーンな仮想環境には、ライブラリをインストールしたibm-cos-sdkを使用しているときに、予期しないキーワード引数 'ibm_api_key_id'がありますか?

virtualenv --python=python3.5 boto-test 
source boto-test/bin/activate 
pip install ibm-cos-sdk 

その後、私は例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)) 

をしかし、実行しているとき、I次の出力を取得します。

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'

私は何か間違っていますか? Shoud私は私のvirtualenvにbotocoreをインストールしますか?

+1

引数とその変数名の順序をあいまいにしていますか? 'ibm_api_key_id = api_key'は' api_key = ibm_api_key'などのように見えます...とにかくキーは 'lbm_api_key'です。あなたが' boto.Client'にアペックスできる引数ではありません。期待している。 –

+0

問題は、これがpipと一緒にインストールしたibmクラウドストレージAPIだということです。彼らの例で少なくとも動作する必要があります。私はまだインストール時に何かをねじ止めしたかどうかを判断しようとしていますが、指示は非常に明確で簡単です。 –

+0

まず、あなたの質問には重要であると言及していますが、それはむしろ疑問です。あなたが新しい空のvirtualenvを作成した後、その中に 'boto3'をインストールして、あなたが言及した適応ライブラリのようにそのboto3を使ってみてください - あなたは上記を得るでしょう... –

答えて

2

編集botocore/credentials.pyと変更インポートhttplib httplib

1

としてhttp.clientをインポートする問題Iを発見した: IBMのライブラリibm-cos-sdk-python-coreは、資格情報には、しかし、botocoreライブラリの独自のバージョンであります.pyのリポジトリからは、Python 3(httplib - > http.client)上で名前が変更されたライブラリへの参照があります。

だから私の修正はからの私のローカルインストールディレクトリにcredentials.pyのライン27を交換することであったに

import httplib 

import http.client as httplib 

場合の未解決の問題がありましたが(#1 )、しかし、私はレポが互いに関係していなかったので私は見なかったし、私はまだIBMのライブラリがどのように働いているのか学んでいる。

関連する問題