0

I am trying to create a client object which I would like to use to upload files to a folder in my Box (as in, the cloud storage method). I am using boxsdk in Python as an API with an application that I just made. I've been using this code, which I found from this question:

from boxsdk import OAuth2
from boxsdk import Client

CLIENT_ID = 'MY CLIENT ID'
CLIENT_SECRET = 'MY SECRET CLIENT'
EMAIL_ADDRESS = 'THE ADMIN EMAIL'


def read_tokens():
    """Reads authorization tokens from keyring"""
    # Use keyring to read the tokens
    auth_token = keyring.get_password('Box_Auth', EMAIL_ADDRESS)
    refresh_token = keyring.get_password('Box_Refresh', EMAIL_ADDRESS)
    return auth_token, refresh_token


def store_tokens(access_token, refresh_token):
    """Callback function when Box SDK refreshes tokens"""
    # Use keyring to store the tokens
    keyring.set_password('Box_Auth', EMAIL_ADDRESS, access_token)
    keyring.set_password('Box_Refresh', EMAIL_ADDRESS, refresh_token)


def main():
    """Authentication against Box Example"""

    # Retrieve tokens from secure store
    access_token, refresh_token = read_tokens()

    # Set up authorisation using the tokens we've retrieved
    oauth = OAuth2(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    access_token=access_token,
    refresh_token=refresh_token,
    store_tokens=store_tokens,
    )

    # Create the SDK client
    client = Client(oauth)
    # Get current user details and display
    current_user = client.user(user_id='me').get()
    print('Box User:', current_user.name)

main()

Right now I am getting this error:

Message: No "refresh_token" parameter found
Status: 400
URL: https://api.box.com/oauth2/token
Method: POST
Headers: {'Date': 'Wed, 19 Oct 2022 17:46:59 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Strict-Transport-Security': 'max-age=31536000', 'Set-Cookie': 'box_visitor_id=63503813debb03.01872716; expires=Thu, 19-Oct-2023 17:46:59 GMT; Max-Age=31536000; path=/; domain=.box.com; secure, bv=OPS-45604; expires=Wed, 26-Oct-2022 17:46:59 GMT; Max-Age=604800; path=/; domain=.app.box.com; secure, cn=30; expires=Thu, 19-Oct-2023 17:46:59 GMT; Max-Age=31536000; path=/; domain=.app.box.com; secure, site_preference=desktop; path=/; domain=.box.com; secure', 'Cache-Control': 'no-store', 'Via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"'}
  • Where, exactly, is this error coming from? The `Oauth2()` call? The `Client()` call? Somewhere else? – John Gordon Oct 19 '22 at 18:01
  • Also, I don't see how this code works at all, because `keyring` is undefined. – John Gordon Oct 19 '22 at 18:02
  • Sorry, I forgot to include this line at the beginning: ```import keyring```. The line of code that returns the error is: ```current_user = client.user(user_id='me').get()``` – Whitesnack Oct 19 '22 at 19:08

0 Answers0