diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2215cf..0e74ce6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log +## v0.7.2 + +* Pydantic model is used for input validation. +* Support NaN, -inf and inf in metadata and metrics. + ## v0.7.0 * Collect CPU, GPU and memory resource metrics. diff --git a/simvue/__init__.py b/simvue/__init__.py index 6b9c85da..d1a83ba7 100644 --- a/simvue/__init__.py +++ b/simvue/__init__.py @@ -2,4 +2,4 @@ from simvue.client import Client from simvue.handler import Handler from simvue.models import RunInput -__version__ = '0.7.1' +__version__ = '0.7.2' diff --git a/simvue/api.py b/simvue/api.py index 8593e95a..435664c4 100644 --- a/simvue/api.py +++ b/simvue/api.py @@ -1,3 +1,5 @@ +import copy +import json import requests from tenacity import retry, wait_exponential, stop_after_attempt @@ -7,6 +9,15 @@ RETRY_MAX = 10 RETRY_STOP = 5 +def set_json_header(headers): + """ + Return a copy of the headers with Content-Type set to + application/json + """ + headers = copy.deepcopy(headers) + headers['Content-Type'] = 'application/json' + return headers + @retry(wait=wait_exponential(multiplier=RETRY_MULTIPLIER, min=RETRY_MIN, max=RETRY_MAX), stop=stop_after_attempt(RETRY_STOP)) def post(url, headers, data, is_json=True): @@ -14,9 +25,9 @@ def post(url, headers, data, is_json=True): HTTP POST with retries """ if is_json: - response = requests.post(url, headers=headers, json=data, timeout=DEFAULT_API_TIMEOUT) - else: - response = requests.post(url, headers=headers, data=data, timeout=DEFAULT_API_TIMEOUT) + data = json.dumps(data) + headers = set_json_header(headers) + response = requests.post(url, headers=headers, data=data, timeout=DEFAULT_API_TIMEOUT) return response @@ -27,8 +38,8 @@ def put(url, headers, data, is_json=True, timeout=DEFAULT_API_TIMEOUT): HTTP PUT with retries """ if is_json: - response = requests.put(url, headers=headers, json=data, timeout=timeout) - else: - response = requests.put(url, headers=headers, data=data, timeout=timeout) + data = json.dumps(data) + headers = set_json_header(headers) + response = requests.put(url, headers=headers, data=data, timeout=timeout) return response