@@ -117,21 +117,22 @@ def json_make_get_request(
117
117
response .raise_for_status ()
118
118
return response .json ()
119
119
120
- def json_make_post_request (
121
- self , endpoint_uri : URI , * args : Any , ** kwargs : Any
122
- ) -> Dict [str , Any ]:
123
- response = self .get_response_from_post_request (endpoint_uri , * args , ** kwargs )
124
- response .raise_for_status ()
125
- return response .json ()
126
-
127
120
def get_response_from_post_request (
128
121
self , endpoint_uri : URI , * args : Any , ** kwargs : Any
129
122
) -> requests .Response :
123
+ kwargs .setdefault ("timeout" , DEFAULT_HTTP_TIMEOUT )
130
124
session = self .cache_and_return_session (
131
125
endpoint_uri , request_timeout = kwargs ["timeout" ]
132
126
)
133
127
return session .post (endpoint_uri , * args , ** kwargs )
134
128
129
+ def json_make_post_request (
130
+ self , endpoint_uri : URI , * args : Any , ** kwargs : Any
131
+ ) -> Dict [str , Any ]:
132
+ response = self .get_response_from_post_request (endpoint_uri , * args , ** kwargs )
133
+ response .raise_for_status ()
134
+ return response .json ()
135
+
135
136
def make_post_request (
136
137
self , endpoint_uri : URI , data : Union [bytes , Dict [str , Any ]], ** kwargs : Any
137
138
) -> bytes :
@@ -150,8 +151,9 @@ def make_post_request(
150
151
else :
151
152
return response .content
152
153
154
+ @staticmethod
153
155
def _handle_streaming_response (
154
- self , response : requests .Response , start : float , timeout : float
156
+ response : requests .Response , start : float , timeout : float
155
157
) -> bytes :
156
158
response_body = b""
157
159
for data in response .iter_content ():
@@ -296,15 +298,6 @@ async def async_get_response_from_post_request(
296
298
response = await session .post (endpoint_uri , * args , ** kwargs )
297
299
return response
298
300
299
- async def async_make_post_request (
300
- self , endpoint_uri : URI , data : Union [bytes , Dict [str , Any ]], ** kwargs : Any
301
- ) -> bytes :
302
- response = await self .async_get_response_from_post_request (
303
- endpoint_uri , data = data , ** kwargs
304
- )
305
- response .raise_for_status ()
306
- return await response .read ()
307
-
308
301
async def async_json_make_post_request (
309
302
self , endpoint_uri : URI , * args : Any , ** kwargs : Any
310
303
) -> Dict [str , Any ]:
@@ -314,6 +307,15 @@ async def async_json_make_post_request(
314
307
response .raise_for_status ()
315
308
return await response .json ()
316
309
310
+ async def async_make_post_request (
311
+ self , endpoint_uri : URI , data : Union [bytes , Dict [str , Any ]], ** kwargs : Any
312
+ ) -> bytes :
313
+ response = await self .async_get_response_from_post_request (
314
+ endpoint_uri , data = data , ** kwargs
315
+ )
316
+ response .raise_for_status ()
317
+ return await response .read ()
318
+
317
319
async def _async_close_evicted_sessions (
318
320
self , timeout : float , evicted_sessions : List [ClientSession ]
319
321
) -> None :
0 commit comments