From a4b5841f781091177c430520634adf4a39146e40 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 20 Feb 2026 02:09:51 +0100 Subject: [PATCH] esim/http_json_api.py: support text/plain response Content-Type Allow returning text/plain Content-Types as 'data' output argument. So far, all the esim/http_json_api functions require a JSON response. However, a specific vendor has a list function where the request is JSON but the response is text/plain CSV data. Allow and return in a dict. Change-Id: Iba6e4cef1048b376050a435a900c0f395655a790 --- pySim/esim/http_json_api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pySim/esim/http_json_api.py b/pySim/esim/http_json_api.py index bb41df38..4423e871 100644 --- a/pySim/esim/http_json_api.py +++ b/pySim/esim/http_json_api.py @@ -256,5 +256,10 @@ class JsonHttpApiFunction(abc.ABC): raise HttpHeaderError(response) if response.content: - return self.decode(response.json()) + if response.headers.get('Content-Type').startswith('application/json'): + return self.decode(response.json()) + elif response.headers.get('Content-Type').startswith('text/plain;charset=UTF-8'): + return { 'data': response.content.decode('utf-8') } + raise HttpHeaderError(f'unimplemented response Content-Type: {response.headers=!r}') + return None