ssl-certificate - SSL证书 - 使用S3访问进行身份验证

给了我一个S3文件来访问bucket ,

任何帮助,不胜感激。

时间:

事实证明答案如下:

r= requests.get('https://ip:port/file_path',verify=False ,cert='pem_file_path')

注意,请参考cert参数以传递pem文件。

开心编码

通过python访问S3的首选方法是使用BOTO3库。

假设你已经配置了密钥和凭证,这是非常简单的。


import boto3


s3list = boto3.resource('s3')


print('Displaying list of Buckets I have access to ')


for bucket in s3list.buckets.all():


 print(bucket.name)



这是使用Boto3上传图像


import boto3


img = open('some.jpg','rb')


s3list.Bucket('mybucket').put_object(Key='some.jpg', Body=img)



这里是我put和从s3 bucket 获取对象的函数。


def putdataons3(localfile, remotefile):


 try:


 bucket = 'yourbucket'


 boto3accesskey = 'your access key'


 boto3secretaccesskey = 'your secret access key'


 boto3client = boto3.client('s3', region_name='eu-central-1', aws_access_key_id=boto3accesskey, aws_secret_access_key=boto3secretaccesskey)


 d = boto3client.put_object(Body=open(localfile, 'rb').read(), Bucket=bucket, Key=remotefile)


 if d['ResponseMetadata']['HTTPStatusCode'] == 200:


 return True


 return False


 except:


 return False



def getdatafroms3(remotefile, localfile, overwrite=True):


 try:


 if overwrite == False:


 if os.path.isfile(localfile):


 return False


 bucket = 'yourbucket'


 boto3accesskey = 'your access key'


 boto3secretaccesskey = 'your secret access key'


 boto3client = boto3.client('s3', region_name='eu-central-1', aws_access_key_id=boto3accesskey, aws_secret_access_key=boto3secretaccesskey)


 d = boto3client.get_object(Bucket=bucket, Key=remotefile)


 if d['ResponseMetadata']['HTTPStatusCode'] == 200:


 f = open(localfile,"wb")


 d = d['Body'].read()


 f.write(d)


 f.close()


 return True


 return False


 except:


 return False



...