Coder Social home page Coder Social logo

Comments (2)

sirosen avatar sirosen commented on May 25, 2024

Hi there, thanks for reporting this! I believe that you're seeing normal behavior, but for a specific case which the example script doesn't explain.
I need to think more about what we do to improve the docs...

That error is thrown when a collection requires explicit consent for operations to run against it.
There's some utility in the SDK for parsing these errors and making them actionable, but there are still significant parts which you would need to fill in.

First, here's the section on parsing ConsentRequired errors. You can identify them like so:

try:
    # do some operations
except globus_sdk.TransferAPIError as err:
    if err.info.consent_required:
        print(
            "Got a ConsentRequired error with scopes:",
            err.info.consent_required.required_scopes,
        )
    else:
        raise

That is, once you have caught an API error, check if err.info.consent_required to see if it's the right type, and if it is, you'll have useful data in required_scopes.

So far, this is maybe non-obvious but it's "easy enough", but the next step can be difficult for some applications.
You need the user (in this case, you) to do a new login flow with the required_scopes from above, and then you need to start using the Transfer API token from that login flow.

If your initial login flow was done with a native app like the SDK tutorial shows, you'll probably have a line like so:

auth_client.oauth2_start_flow()

The correct modification is just

# where `required_scopes` is the value we got from exception handling earlier on a
# ConsentRequired error
auth_client.oauth2_start_flow(requested_scopes=required_scopes)

In the globus-cli, the way we've solved this is that tokens are stored using globus_sdk.tokenstorage, and we have a dedicated command (globus session consent) which updates the tokens which are in storage.
In effect, the globus-cli error handler looks like this:

try:
    # do some operations
except globus_sdk.TransferAPIError as err:
    if err.info.consent_required:
        print("Error: ConsentRequired during Transfer operation")
        print("Please run the following command and then try again:")
        print()
        print(f"    globus session consent '{err.info.consent_required.required_scopes}'")
        print()
    else:
        raise

Depending on the exact nature of your code (a script, an application, etc), this may or may not be easy for you to handle in a similar way.

I would recommend that if you are not already using it that you start using globus_sdk.tokenstorage -- it will probably make it easier for you to follow the pattern we've established with the globus-cli. This example shows some pretty complete usage, so it might be a good jumping-off point for you.


I'm keeping this open because I think we should do something on that example page to document what I've written here. Possibly we should add a second larger example to the same page to handle this case.

from globus-sdk-python.

sirosen avatar sirosen commented on May 25, 2024

We have detailed handling examples going out in our next release, and currently visible here:
https://globus-sdk-python.readthedocs.io/en/latest/examples/minimal_transfer_script/index.html

As such, I think we're able to close this as resolved.

from globus-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.