Code: Select all
# these are two functions that I use
def create_iterator(s3_client,bname):
# create a paginator (without this the maximum number of objects returned is 1000)
try:
paginator = s3_client.get_paginator('list_objects_v2')
except ClientError as e:
print(f"Error creating list_objects_v2 paginator: {e}")
sys.exit(1)
# create a page iterator which returns a page of objects at a time (up to 1000 objects per page)
try:
page_iterator = paginator.paginate(Bucket=bname)
except ClientError as e:
print(f"Error creating pageinate for bucket {bname}: {e}")
sys.exit(1)
def print_objectlist(s3_client,bname,format):
piterator = create_iterator(s3_client,bname)
objcnt=0
for page in piterator:
# assign the Contents array of objects to the objarray variable for this page
objarray=page['Contents']
for obj in objarray:
objcnt += 1
print(f' {obj["Key"]}')
Code: Select all
def main():
import sys
# a bunch of code here that establishes the s3_client validates the values
# in the BNAME and OFORMAT variables
print_objectlist(s3_client, BNAME, OFORMAT)
Es sieht so aus, als würde der Fehler ausgegeben, wenn ich versuche, über den Piterator zu iterieren (für Seite in Piterator:). Ich weiß, dass der BNAME, den ich als Parameter übergebe, tatsächlich existiert. Ein Teil des Codes, der den BNAME-Parameter validiert, führt zunächst einen list_buckets-Aufruf auf dem s3_client durch und prüft die zurückgegebene Liste anhand der BNAME-Variablen, um sicherzustellen, dass sie gültig ist.
Ich würde erwarten, dass, wenn der Bucket-Name falsch wäre, der try: .... außer:-Block mit page_iterator = paginator.paginate(Bucket=bname) fehlschlagen würde, aber stattdessen scheint der page_iterator erstellt zu werden und Der Code schlägt fehl, wenn ich versuche, über die Variable page_iterator zu iterieren. Hier ist der Traceback, wenn ich den Code ausführe:
Code: Select all
Traceback (most recent call last):
File "/ascldap/users/jsebast/9737_Knowledge_Systems/Projects/RDMIP/ECS/ecs_python_scripts/list_objects_in_ecs_bucket.py", line 244, in
main()
^^^^^^
File "/ascldap/users/jsebast/9737_Knowledge_Systems/Projects/RDMIP/ECS/ecs_python_scripts/list_objects_in_ecs_bucket.py", line 238, in main
print_objectlist(s3_client, BNAME, OFORMAT)
File "/ascldap/users/jsebast/9737_Knowledge_Systems/Projects/RDMIP/ECS/ecs_python_scripts/list_objects_in_ecs_bucket.py", line 82, in print_objectlist
for page in piterator:
^^^^^^^^^
File "/ascldap/users/jsebast/.local/lib/python3.12/site-packages/botocore/paginate.py", line 272, in __iter__
response = self._make_request(current_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/ascldap/users/jsebast/.local/lib/python3.12/site-packages/botocore/context.py", line 123, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/ascldap/users/jsebast/.local/lib/python3.12/site-packages/botocore/paginate.py", line 360, in _make_request
return self._method(**current_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/ascldap/users/jsebast/.local/lib/python3.12/site-packages/botocore/client.py", line 602, in _api_call
return self._make_api_call(operation_name, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/ascldap/users/jsebast/.local/lib/python3.12/site-packages/botocore/context.py", line 123, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/ascldap/users/jsebast/.local/lib/python3.12/site-packages/botocore/client.py", line 1078, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjectsV2 operation: The specified bucket does not exist.
Mobile version