Forum Discussion

smpa01's avatar
smpa01
Community Champion
1 year ago

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

9 Replies

  • Anonymous's avatar
    Anonymous
    Not 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

    • smpa01's avatar
      smpa01
      Community 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 ?