Giter Site home page Giter Site logo

Comments (5)

mullenkamp avatar mullenkamp commented on August 24, 2024 2

Thank you very much @ppolewicz , your solution does seem to work and I understand what's going on.
Maybe a brief mention of this in the docs would be helpful, because the tutorial only uses the InMemoryAccountInfo as I described.
Thanks again

from b2-sdk-python.

mullenkamp avatar mullenkamp commented on August 24, 2024 1

Thanks for the reply. But it's still unclear when (and how) that cache gets updated with the bucket id and bucket name.

Following the tutorial (with real keys of course):

from b2sdk.v2 import InMemoryAccountInfo, B2Api

info = B2Api.InMemoryAccountInfo()
b2_api = B2Api.B2Api(info)
b2_api.authorize_account("production", 'fake_key_id', 'fake_key')

bucket = b2_api.get_bucket_by_id('fake_bucket_id')

The last line fails with an Unauthorized: unauthorized for application key with capabilities error.
Is there a step I'm missing?
The key that I'm using has read and write access to the files.

Thanks again

from b2-sdk-python.

mjurbanski-reef avatar mjurbanski-reef commented on August 24, 2024 1

Seems the source of your problem to be in:

if account_info is None:
account_info = self.SQLITE_ACCOUNT_INFO_CLASS()
if cache is None:
cache = AuthInfoCache(account_info)
if cache is None:
cache = DummyCache()

I have to look more into this behavior, as my first instinct would be to change it, but we have a strong non-breaking changes policy.

In short, if AccountInfo is manually passed, then cache object is not automagically created for API and it is to expected to be passed in, explicitly, as you did with AccountInfo, i.e.

from b2sdk.v2 import B2Api, InMemoryAccountInfo, InMemoryCache

info = InMemoryAccountInfo()
b2_api = B2Api(
    info,
    cache=InMemoryCache()  # Without this line Bucket-specific Key with only readFiles capability won't work
)

from b2-sdk-python.

ppolewicz avatar ppolewicz commented on August 24, 2024

You can use a key restricted to a bucket - in this case b2 account authorize will pre-fill the bucket id-to-name cache and you shouldn't need list_buckets

from b2-sdk-python.

mjurbanski-reef avatar mjurbanski-reef commented on August 24, 2024

To avoid breaking changes, the change was made to yet not stable b2sdk._v3 interface, while b2sdk.v2 stays as it was, but fixed documentation of to recommend:

from b2sdk.v2 import B2Api, InMemoryAccountInfo, AuthInfoCache

info = InMemoryAccountInfo()
b2_api = B2Api(
    info,
    cache=AuthInfoCache(info)
)

where as in b2sdk.v3 the manual creation of AuthInfoCache won't be required to attain the exactly same effect (i.e. having a working bucket cache).

from b2-sdk-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.