Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b44fce1c authored by CAMPION Sebastien's avatar CAMPION Sebastien
Browse files

fix problem of API legacy from server

parent 5369b4c0
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ except ImportError: ...@@ -13,7 +13,7 @@ except ImportError:
import requests import requests
log = logging.getLogger('allgo') log = logging.getLogger('allgo')
__version__ = '0.1.8' __version__ = '0.1.9'
def local_token(): def local_token():
...@@ -66,14 +66,20 @@ class App: ...@@ -66,14 +66,20 @@ class App:
r = requests.post(url, headers=headers, files=files, data=data, verify=verify_tls) r = requests.post(url, headers=headers, files=files, data=data, verify=verify_tls)
r.raise_for_status() r.raise_for_status()
r = r.json() r = r.json()
jobid = r['id'] if 'id' in r.keys():
jobid = r['id']
else:
jobid = list(r.keys())[0]
results = None results = None
while True: while True:
url = '{}/api/v1/jobs/{}'.format(ALLGO_URL, jobid) url = '{}/api/v1/jobs/{}'.format(ALLGO_URL, jobid)
r = requests.get(url, headers=headers, verify=verify_tls) r = requests.get(url, headers=headers, verify=verify_tls)
r.raise_for_status() r.raise_for_status()
results = r.json() results = r.json()
status = results['status'] if 'status' in results.keys():
status = results['status']
else:
status = list(results.values())[0]['status']
if status in ['created', 'waiting', 'running', 'in progress']: if status in ['created', 'waiting', 'running', 'in progress']:
log.info("wait for job %s in status %s", jobid, status) log.info("wait for job %s in status %s", jobid, status)
time.sleep(2) time.sleep(2)
...@@ -84,7 +90,15 @@ class App: ...@@ -84,7 +90,15 @@ class App:
raise Exception('Job %s failed with status %s', (jobid, status)) raise Exception('Job %s failed with status %s', (jobid, status))
elif status == 'done' and results: elif status == 'done' and results:
for filename, url in results[str(jobid)].items(): if 'id' in results.keys():
files = results[str(jobid)].items()
else:
files = results[str(jobid)]['files'].items()
for filename, url in files:
filepath = os.path.join(outputdir, filename) filepath = os.path.join(outputdir, filename)
with open(filepath, 'wb') as fb: with requests.get(url, headers=headers, verify=verify_tls, stream=True) as r:
fb.write(requests.get(url, stream=True).content) r.raise_for_status()
with open(filepath, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment