2016-11-08 118 views
-1
[[email protected] Desktop]# python 
Python 2.7.5 (default, Sep 15 2016, 22:37:39) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import boto3 
>>> s3=boto3.resources('s3') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'module' object is not callable 

回答

0

我相信閱讀文檔不會造成任何傷害。你可以找到這個here。它向您展示瞭如何爲boto3中的每個服務創建一個客戶端,以及如何調用該服務的操作。

嘗試以下操作:

# Import the boto3 library 
import boto3 

# Create a client that can access S3 on your behalf using your Access key and Secret key 
client = boto3.client(
    's3', 
    aws_access_key_id=YOUR_ACCESS_KEY, 
    aws_secret_access_key=YOUR_SECRET_KEY 
) 

# Example operation 

response = client.list_objects(
    Bucket='YOUR_BUCKET_NAME' 
) 

print response 
1

reources是一個模塊,resource是一個函數,它是你正在尋找的人。

>>> boto3.resources 
<module 'boto3.resources' from '/usr/local/lib/python2.7/site-packages/boto3/resources/__init__.pyc'> 
>>> boto3.resource 
<function resource at 0x7fbf18615410> 
>>> from boto3 import resources 

所以,你應該叫resource

s3=boto3.resource('s3')