11
11
from urllib .parse import urlencode
12
12
13
13
import 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
15
15
16
16
from apify_client ._logging import log_context , logger_name
17
17
from apify_client ._statistics import Statistics
18
18
from 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
20
20
21
21
if TYPE_CHECKING :
22
22
from collections .abc import Callable
@@ -65,25 +65,6 @@ def __init__(
65
65
66
66
self .stats = stats or Statistics ()
67
67
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
-
87
68
@staticmethod
88
69
def _parse_params (params : dict | None ) -> dict | None :
89
70
if params is None :
@@ -159,17 +140,13 @@ def call(
159
140
data : Any = None ,
160
141
json : JSONSerializable | None = None ,
161
142
stream : bool | None = None ,
162
- parse_response : bool | None = True ,
163
143
timeout_secs : int | None = None ,
164
144
) -> impit .Response :
165
145
log_context .method .set (method )
166
146
log_context .url .set (url )
167
147
168
148
self .stats .calls += 1
169
149
170
- if stream and parse_response :
171
- raise ValueError ('Cannot stream response and parse it at the same time!' )
172
-
173
150
headers , params , content = self ._prepare_request_call (headers , params , data , json )
174
151
175
152
impit_client = self .impit_client
@@ -198,11 +175,6 @@ def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response:
198
175
# If response status is < 300, the request was successful, and we can return the result
199
176
if response .status_code < 300 : # noqa: PLR2004
200
177
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
206
178
207
179
return response
208
180
@@ -247,17 +219,13 @@ async def call(
247
219
data : Any = None ,
248
220
json : JSONSerializable | None = None ,
249
221
stream : bool | None = None ,
250
- parse_response : bool | None = True ,
251
222
timeout_secs : int | None = None ,
252
223
) -> impit .Response :
253
224
log_context .method .set (method )
254
225
log_context .url .set (url )
255
226
256
227
self .stats .calls += 1
257
228
258
- if stream and parse_response :
259
- raise ValueError ('Cannot stream response and parse it at the same time!' )
260
-
261
229
headers , params , content = self ._prepare_request_call (headers , params , data , json )
262
230
263
231
impit_async_client = self .impit_async_client
@@ -283,11 +251,6 @@ async def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response
283
251
# If response status is < 300, the request was successful, and we can return the result
284
252
if response .status_code < 300 : # noqa: PLR2004
285
253
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
291
254
292
255
return response
293
256
0 commit comments