from qcloud_cos3 import CosConfig from qcloud_cos3 import CosS3Client config = CosConfig(Region='ap-shanghai', Secret_id='xxxxxxxxxxxx', Secret_key='xxxxxxxxxxx', Token=None) # 获取配置对象 client = CosS3Client(config) Marker = "" response = "" total =0 while True: # 判断Marker是否存在,Marker是分页的起点位置从什么位置开始查询 if Marker == "": response = client.list_objects( Bucket='pub-10000178', Prefix='hhtpreview/0', ) else: response = client.list_objects( Bucket='pub-10000178', Prefix='hhtpreview/0', Marker=Marker, ) #判断response字典里面是否存在NextMarker这个key if 'NextMarker' in response.keys() : Marker = response['NextMarker'] print(response['NextMarker']) else: print("NextMarker not exists") Marker ='' for j,i in enumerate(response['Contents']): # print(i['Size']) total +=int(i['Size']) if Marker == '': break print(total) # print(round(int(j['Size'])/1024)) # print(round(int(j['Size'])/1024)) # print("size: %s" % j['Size'])