1111from urllib .parse import urlencode
1212
1313import impit
14- from apify_shared .utils import ignore_docs , is_content_type_json , is_content_type_text , is_content_type_xml
14+ from apify_shared .utils import ignore_docs
1515
1616from apify_client ._logging import log_context , logger_name
1717from apify_client ._statistics import Statistics
1818from apify_client ._utils import is_retryable_error , retry_with_exp_backoff , retry_with_exp_backoff_async
19- from apify_client .errors import ApifyApiError , InvalidResponseBodyError
19+ from apify_client .errors import ApifyApiError
2020
2121if TYPE_CHECKING :
2222 from collections .abc import Callable
@@ -65,25 +65,6 @@ def __init__(
6565
6666 self .stats = stats or Statistics ()
6767
68- @staticmethod
69- def _maybe_parse_response (response : impit .Response ) -> Any :
70- if response .status_code == HTTPStatus .NO_CONTENT :
71- return None
72-
73- content_type = ''
74- if 'content-type' in response .headers :
75- content_type = response .headers ['content-type' ].split (';' )[0 ].strip ()
76-
77- try :
78- if is_content_type_json (content_type ):
79- return jsonlib .loads (response .text )
80- elif is_content_type_xml (content_type ) or is_content_type_text (content_type ): # noqa: RET505
81- return response .text
82- else :
83- return response .content
84- except ValueError as err :
85- raise InvalidResponseBodyError (response ) from err
86-
8768 @staticmethod
8869 def _parse_params (params : dict | None ) -> dict | None :
8970 if params is None :
@@ -159,17 +140,13 @@ def call(
159140 data : Any = None ,
160141 json : JSONSerializable | None = None ,
161142 stream : bool | None = None ,
162- parse_response : bool | None = True ,
163143 timeout_secs : int | None = None ,
164144 ) -> impit .Response :
165145 log_context .method .set (method )
166146 log_context .url .set (url )
167147
168148 self .stats .calls += 1
169149
170- if stream and parse_response :
171- raise ValueError ('Cannot stream response and parse it at the same time!' )
172-
173150 headers , params , content = self ._prepare_request_call (headers , params , data , json )
174151
175152 impit_client = self .impit_client
@@ -198,11 +175,6 @@ def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response:
198175 # If response status is < 300, the request was successful, and we can return the result
199176 if response .status_code < 300 : # noqa: PLR2004
200177 logger .debug ('Request successful' , extra = {'status_code' : response .status_code })
201- if not stream :
202- _maybe_parsed_body = (
203- self ._maybe_parse_response (response ) if parse_response else response .content
204- )
205- setattr (response , '_maybe_parsed_body' , _maybe_parsed_body ) # noqa: B010
206178
207179 return response
208180
@@ -247,17 +219,13 @@ async def call(
247219 data : Any = None ,
248220 json : JSONSerializable | None = None ,
249221 stream : bool | None = None ,
250- parse_response : bool | None = True ,
251222 timeout_secs : int | None = None ,
252223 ) -> impit .Response :
253224 log_context .method .set (method )
254225 log_context .url .set (url )
255226
256227 self .stats .calls += 1
257228
258- if stream and parse_response :
259- raise ValueError ('Cannot stream response and parse it at the same time!' )
260-
261229 headers , params , content = self ._prepare_request_call (headers , params , data , json )
262230
263231 impit_async_client = self .impit_async_client
@@ -283,11 +251,6 @@ async def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response
283251 # If response status is < 300, the request was successful, and we can return the result
284252 if response .status_code < 300 : # noqa: PLR2004
285253 logger .debug ('Request successful' , extra = {'status_code' : response .status_code })
286- if not stream :
287- _maybe_parsed_body = (
288- self ._maybe_parse_response (response ) if parse_response else response .content
289- )
290- setattr (response , '_maybe_parsed_body' , _maybe_parsed_body ) # noqa: B010
291254
292255 return response
293256
0 commit comments