Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
smpa01
Super User
Super User

Refresh Token Expiry

@peggysue @gbrueckl 

 

I have been runing batch jobs and the token is getting expired ~60/75 min.

 

// header
<CIMultiDictProxy('Content-Length': '104', 'Content-Type': 'application/json; charset=utf-8', 'X-PowerBI-Error-Info': 'TokenExpired', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'Access-Control-Expose-Headers': 'RequestId,X-PowerBI-Error-Info', 'RequestId': 'f098269c-d1b1-473f-86ae-3da25c0b6555', 'Date': 'Tue, 08 Oct 2024 17:15:34 GMT')>

 

 

I tried this but this is not consistent. I desparately need the bacth job to run without getting terminated in between and without needing me to babysit.

 

 

 

from datetime import datetime, timezone
import pytz
import requests


def current_hour ():
    current_time = datetime.now(pytz.timezone('America/Toronto'))
    hour = current_time.hour
    text_hour = str(hour)
    return text_hour

token = notebookutils.credentials.getToken('pbi')  

service_call = requests.get(uri, headers={"authorization": "Bearer " + token,"VariableHeader": current_hour()}) 

 

 

 

Thank you in advance

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
9 REPLIES 9
v-shex-msft
Community Support
Community Support

HI @smpa01,

Perhaps you can try to modify the session timeout of the notebook, you can click on the left-bottom session icon to open session information panel.

1.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft  Thanks for this and I will take this out on a spin and let u know.

 

1 question though - Assuming it works, if I am running batchJob.ipynb with the scheduler at nth hour every day, how can I ensure that it runs with the same custom session timeout (e.g. 90 min) everyday? Asked differently, is the same custom session timeout value applies to the notebook on each run and ca different notebooks have different custom session timeout values ?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

HI @smpa01,

You can open the workspace setting to modify the spark session timeout.

1.png

In addition, you can also consider to use high concurrency mode to running your notebook:
Configure high concurrency mode for notebooks - Microsoft Fabric | Microsoft Learn

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

please give me few days to test it out.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

HI @smpa01,

Sure, you can feel free post here if the above not helps.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft  if the notebook is run on a schedule, the token expiry still happens. But if I run the notebook is run from while inside it, then the token does not expire.

 

I want to run the notebook on a schedule.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

HI @smpa01,

As you said, it seems like these setting does not enable when you setting schreuder on it. Have you tried to use high concurrency mode to processing your notebook, it should allow to use more resource on it.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Unfortunately nothing is working, on scheduled job , the token is getting expired around 63-66 min mark (with 90 min timeout session default). I am also not sure if you can defualt a notebook to run with a HC mode. I can only turn on HC mode when inside it.

 

It is probably because, if I follow this , I get

 

 

{
    "token_type": "Bearer",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "loremIpsum"
}

 

 

How can I refresh this token or get access to a reresh token that can be used to API calls nearing 60 min mark

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01,

 

When do you create the Bearer token and do you re-use the Bearer token over multiple notebook sessions? If you do, you may retrieve the Bearer token in every session instead, so you are less likely to exceed the 1h limit of the Bearer token.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.