No such bucket
Closed this issue · 5 comments
retorquere commented
When I run this:
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv(), override=True)
import os
from b2sdk.v2 import InMemoryAccountInfo
from b2sdk.v2 import B2Api
b2_api = B2Api(InMemoryAccountInfo())
b2_api.authorize_account('production', os.environ['B2_APPLICATION_KEY_ID'], os.environ['B2_APPLICATION_KEY'])
bucket_id = b2_api.get_bucket_by_name(f'b2://apt-package-archive')
print(bucket_id)
bucket = parse_sync_folder(bucket_id, b2_api)
for file_info, folder_name in bucket.ls():
print(file_info)
I get
Traceback (most recent call last):
File "/Users/emile/github/debs/wtf.py", line 12, in <module>
bucket_id = b2_api.get_bucket_by_name(f'b2://apt-package-archive')
File "/usr/local/lib/python3.10/site-packages/b2sdk/api.py", line 319, in get_bucket_by_name
raise NonExistentBucket(bucket_name)
b2sdk.exception.NonExistentBucket: No such bucket: b2://apt-package-archive
Where I am sure the bucket exists, and it is more than 10 minutes old.
retorquere commented
It seems to be the translation of the name to an ID. This works:
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv(), override=True)
import os
from b2sdk.v2 import InMemoryAccountInfo
from b2sdk.v2 import B2Api
from b2sdk.v2 import parse_sync_folder
b2_api = B2Api(InMemoryAccountInfo())
b2_api.authorize_account('production', os.environ['B2_APPLICATION_KEY_ID'], os.environ['B2_APPLICATION_KEY'])
bucket_id = 'cde28975291c718879f20b1b'
bucket = b2_api.get_bucket_by_id(bucket_id)
# b2_api.get_bucket_by_name(f'b2://apt-package-archive')
# bucket = parse_sync_folder(bucket_id, b2_api)
for file_info, folder_name in bucket.ls():
print(file_info)
where cde28975291c718879f20b1b
is the ID of apt-package-archive
, taken from the web UI.
ppolewicz commented
Is the bucket name b2://apt-package-archive
or apt-package-archive
? ;)
retorquere commented
Do'h!
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv(), override=True)
import os
from b2sdk.v2 import InMemoryAccountInfo
from b2sdk.v2 import B2Api
from b2sdk.v2 import parse_sync_folder
b2_api = B2Api(InMemoryAccountInfo())
b2_api.authorize_account('production', os.environ['B2_APPLICATION_KEY_ID'], os.environ['B2_APPLICATION_KEY'])
bucket = parse_sync_folder('b2://apt-package-archive', b2_api)
for file_info, folder_name in bucket.ls():
print(file_info)
gets me
AttributeError: 'B2Folder' object has no attribute 'ls'
ppolewicz commented
parse_sync_folder
returns a B2Folder
object, not a Bucket
. Please consult the documentation :)
retorquere commented
argh. sorry.