2016-11-08 109 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')