From e2ec0347f68dbea31eda761144a7f435cb625f19 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pySim/esim/http_json_api.py b/pySim/esim/http_json_api.py index 0220d2523..77e0b8d9a 100644 --- a/pySim/esim/http_json_api.py +++ b/pySim/esim/http_json_api.py @@ -411,20 +411,30 @@ class JsonHttpApiClient(): # SGP.22, section 6.5.1) if response.status_code != self.api_func.expected_http_status: raise HttpStatusError(response) - if response.content and not response.headers.get('Content-Type').startswith(req_headers['Content-Type']): + + resp_content_type = response.headers.get('Content-Type') + if response.content and not resp_content_type.startswith(req_headers['Content-Type']): raise HttpHeaderError(response) + if not response.headers.get('X-Admin-Protocol', 'gsma/rsp/v2.unknown').startswith('gsma/rsp/v2.'): raise HttpHeaderError(response) # Decode response and return the result back to the caller if response.content: - output = self.api_func.decode_client(response.json()) + if resp_content_type.startswith('application/json'): + output = self.api_func.decode_client(response.json()) + elif resp_content_type.startswith('text/plain;charset=UTF-8'): + output = { 'data': response.content.decode('utf-8') } + else: + raise HttpHeaderError(f'unimplemented response Content-Type: {response.headers=!r}') + # In case the response contains a header, check it to make sure that the API call was executed successfully # (the presence of the header field is checked by the decode_client method) if 'header' in output: if output['header']['functionExecutionStatus']['status'] not in ['Executed-Success','Executed-WithWarning']: raise ApiError(output['header']['functionExecutionStatus']) return output + return None class JsonHttpApiServer():