Forum Discussion
Refresh Token Expiry
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
9 Replies
- AnonymousNot applicable
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.
Regards,
Xiaoxin Sheng
- smpa01Community Champion
Anonymous 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 ?
- AnonymousNot applicable
HI smpa01,
You can open the workspace setting to modify the spark session timeout.
In addition, you can also consider to use high concurrency mode to running your notebook:
Configure high concurrency mode for notebooks - Microsoft Fabric | Microsoft LearnRegards,
Xiaoxin Sheng