@@ -218,7 +218,7 @@ def _request_for_pagination(self, api_url: str, req_args: Dict[str, Dict[str, An
218218 return {
219219 "status_code" : int (response ["status" ]),
220220 "headers" : dict (response ["headers" ]),
221- "data" : json .loads (response ["body" ]),
221+ "data" : response [ "parsed_body" ] if "parsed_body" in response else json .loads (response ["body" ]),
222222 }
223223
224224 def _urllib_api_call (
@@ -306,7 +306,9 @@ def convert_params(values: dict) -> dict:
306306 response = self ._perform_urllib_http_request (url = url , args = request_args ) # type: ignore[arg-type]
307307 response_body = response .get ("body" , None )
308308 response_body_data : Optional [Union [dict , bytes ]] = response_body
309- if response_body is not None and not isinstance (response_body , bytes ):
309+ if "parsed_body" in response :
310+ response_body_data = response ["parsed_body" ]
311+ elif response_body is not None and not isinstance (response_body , bytes ):
310312 try :
311313 response_body_data = json .loads (response ["body" ])
312314 except json .decoder .JSONDecodeError :
@@ -413,13 +415,14 @@ def _perform_urllib_http_request(self, *, url: str, args: Dict[str, Dict[str, An
413415 body_string = resp ["body" ] if isinstance (resp ["body" ], str ) else None
414416 body_bytes = body_string .encode ("utf-8" ) if body_string is not None else resp ["body" ]
415417 if body_string is not None and body_string .startswith ("{" ):
416- body = json .loads (body_string )
418+ parsed_body = json .loads (body_string )
419+ resp ["parsed_body" ] = parsed_body
417420 else :
418- body = {} # type: ignore[assignment]
421+ parsed_body = {}
419422 retry_response = RetryHttpResponse (
420423 status_code = resp ["status" ],
421424 headers = resp ["headers" ],
422- body = body , # type: ignore[arg-type]
425+ body = parsed_body ,
423426 data = body_bytes ,
424427 )
425428 for handler in self .retry_handlers :
0 commit comments