[root@localhost 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 :(得分: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')
答案 1 :(得分: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