Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

how to sign out (for unit-testing reconnection after login timeout)?

Open nmz787-intel opened this issue 3 years ago • 0 comments

I have experienced the connection timing out, after hours/days (not sure which). I get an error message like 401 Client Error: Unauthorized for url.

I built a decorator for my functions that use o365, and in the decorator I call the function inside a try/except that looks for that 401 string, and if found calls my login function then the wrapped function again.

for unit-testing though, how can I forcibly log/sign out of the ClientContext?

Here's my login function for reference:

def login():
    print('logging into SharePoint!')
    global existing_login
    context_auth = AuthenticationContext(site)
    token = context_auth.acquire_token_for_app(client_id=user, client_secret=passw)
    if token:
        ctx = ClientContext(site, context_auth)
        web = ctx.web
        ctx.load(web)
        ctx.execute_query()
        #print("Web site title: {0}".format(web.properties['Title']))
        existing_login = ctx
        return ctx
    return False

nmz787-intel avatar Mar 30 '22 20:03 nmz787-intel