Forum

Message Boards Message Boards

Back

Refresh KeyCloakToken during download

Refresh KeyCloakToken during download
Answer
5 March 2020 8:39
Hi everyone,
I created a Python script to query the CREODIAS archive using the Finder API and then download some data. Unfortunately, the download speed on the machine the script is running on is quite slow and causes the KeyCloakToken to expire (just learned that it is only valid for 300 seconds). I do something like this:
123456789
import requests
# some stuff to set up the query and and figure out the scene_id for downloading, then:
token = getKeyCloudToken() # own function to retrieve the token
download_url = BASE_URL + '/{sceneid}?token={t}'.format(sceneid=scene_id, t=token)
response = requests.get(download_url, stream=True)
# do the actual download
with open(outfile, 'wb') as f:
    for chunk in response.iter_content(chunk_size=1024*1024):
        f.write(chunk)
The download then just quits after 300 seconds without any warning or error. Is there any way how I can retrieve a new KeyCloakToken after these 300 seconds and continue the download without restarting it?
Thanks a lot in advance!
0 (0 Votes)