1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| from boto3.session import Session from botocore.config import Config import os os.environ["HTTP_PROXY"] = "http://proxy:9999" os.environ["HTTPS_PROXY"] = "https://proxy:9999"
access_key = "username" secret_key = "password" url = "http://localhost:9000"
session = Session(access_key, secret_key) session = Session(access_key, secret_key) s3_client = session.client('s3', endpoint_url=url)
print([bucket['Name'] for bucket in s3_client.list_buckets()['Buckets']])
resp = s3_client.list_objects(Bucket="data", Delimiter='/', Prefix='spider/') for path in resp.get("CommonPrefixes"): print(path.get("Prefix"))
resp = s3_client.get_object(Bucket="data", Key="2.pdf") with open("aa.pdf", "wb") as f: f.write(resp["Body"].read())
|