@@ -112,6 +112,10 @@ def image_blur_func(
112
112
import cv2 as cv # type: ignore
113
113
import numpy as np
114
114
import requests
115
+ from requests import adapters
116
+
117
+ session = requests .Session ()
118
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
115
119
116
120
ext = ext or ".jpeg"
117
121
@@ -121,7 +125,7 @@ def image_blur_func(
121
125
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
122
126
dst_url = dst_obj_ref_rt_json ["access_urls" ]["write_url" ]
123
127
124
- response = requests .get (src_url )
128
+ response = session .get (src_url , timeout = 30 )
125
129
bts = response .content
126
130
127
131
nparr = np .frombuffer (bts , np .uint8 )
@@ -135,12 +139,13 @@ def image_blur_func(
135
139
ext = ext_mappings .get (ext , ext )
136
140
content_type = "image/" + ext
137
141
138
- requests .put (
142
+ session .put (
139
143
url = dst_url ,
140
144
data = bts ,
141
145
headers = {
142
146
"Content-Type" : content_type ,
143
147
},
148
+ timeout = 30 ,
144
149
)
145
150
146
151
return dst_obj_ref_rt
@@ -157,13 +162,17 @@ def image_blur_to_bytes_func(
157
162
import cv2 as cv # type: ignore
158
163
import numpy as np
159
164
import requests
165
+ from requests import adapters
166
+
167
+ session = requests .Session ()
168
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
160
169
161
170
ext = ext or ".jpeg"
162
171
163
172
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
164
173
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
165
174
166
- response = requests .get (src_url )
175
+ response = session .get (src_url , timeout = 30 )
167
176
bts = response .content
168
177
169
178
nparr = np .frombuffer (bts , np .uint8 )
@@ -193,6 +202,10 @@ def image_resize_func(
193
202
import cv2 as cv # type: ignore
194
203
import numpy as np
195
204
import requests
205
+ from requests import adapters
206
+
207
+ session = requests .Session ()
208
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
196
209
197
210
ext = ext or ".jpeg"
198
211
@@ -202,7 +215,7 @@ def image_resize_func(
202
215
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
203
216
dst_url = dst_obj_ref_rt_json ["access_urls" ]["write_url" ]
204
217
205
- response = requests .get (src_url )
218
+ response = session .get (src_url , timeout = 30 )
206
219
bts = response .content
207
220
208
221
nparr = np .frombuffer (bts , np .uint8 )
@@ -216,12 +229,13 @@ def image_resize_func(
216
229
ext = ext_mappings .get (ext , ext )
217
230
content_type = "image/" + ext
218
231
219
- requests .put (
232
+ session .put (
220
233
url = dst_url ,
221
234
data = bts ,
222
235
headers = {
223
236
"Content-Type" : content_type ,
224
237
},
238
+ timeout = 30 ,
225
239
)
226
240
227
241
return dst_obj_ref_rt
@@ -245,13 +259,17 @@ def image_resize_to_bytes_func(
245
259
import cv2 as cv # type: ignore
246
260
import numpy as np
247
261
import requests
262
+ from requests import adapters
263
+
264
+ session = requests .Session ()
265
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
248
266
249
267
ext = ext or ".jpeg"
250
268
251
269
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
252
270
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
253
271
254
- response = requests .get (src_url )
272
+ response = session .get (src_url , timeout = 30 )
255
273
bts = response .content
256
274
257
275
nparr = np .frombuffer (bts , np .uint8 )
@@ -280,6 +298,10 @@ def image_normalize_func(
280
298
import cv2 as cv # type: ignore
281
299
import numpy as np
282
300
import requests
301
+ from requests import adapters
302
+
303
+ session = requests .Session ()
304
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
283
305
284
306
ext = ext or ".jpeg"
285
307
@@ -296,7 +318,7 @@ def image_normalize_func(
296
318
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
297
319
dst_url = dst_obj_ref_rt_json ["access_urls" ]["write_url" ]
298
320
299
- response = requests .get (src_url )
321
+ response = session .get (src_url , timeout = 30 )
300
322
bts = response .content
301
323
302
324
nparr = np .frombuffer (bts , np .uint8 )
@@ -312,12 +334,13 @@ def image_normalize_func(
312
334
ext = ext_mappings .get (ext , ext )
313
335
content_type = "image/" + ext
314
336
315
- requests .put (
337
+ session .put (
316
338
url = dst_url ,
317
339
data = bts ,
318
340
headers = {
319
341
"Content-Type" : content_type ,
320
342
},
343
+ timeout = 30 ,
321
344
)
322
345
323
346
return dst_obj_ref_rt
@@ -336,6 +359,10 @@ def image_normalize_to_bytes_func(
336
359
import cv2 as cv # type: ignore
337
360
import numpy as np
338
361
import requests
362
+ from requests import adapters
363
+
364
+ session = requests .Session ()
365
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
339
366
340
367
ext = ext or ".jpeg"
341
368
@@ -349,7 +376,7 @@ def image_normalize_to_bytes_func(
349
376
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
350
377
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
351
378
352
- response = requests .get (src_url )
379
+ response = session .get (src_url , timeout = 30 )
353
380
bts = response .content
354
381
355
382
nparr = np .frombuffer (bts , np .uint8 )
@@ -374,11 +401,15 @@ def pdf_extract_func(src_obj_ref_rt: str) -> str:
374
401
375
402
from pypdf import PdfReader # type: ignore
376
403
import requests
404
+ from requests import adapters
405
+
406
+ session = requests .Session ()
407
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
377
408
378
409
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
379
410
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
380
411
381
- response = requests .get (src_url , stream = True )
412
+ response = session .get (src_url , timeout = 30 , stream = True )
382
413
response .raise_for_status ()
383
414
pdf_bytes = response .content
384
415
@@ -403,11 +434,15 @@ def pdf_chunk_func(src_obj_ref_rt: str, chunk_size: int, overlap_size: int) -> s
403
434
404
435
from pypdf import PdfReader # type: ignore
405
436
import requests
437
+ from requests import adapters
438
+
439
+ session = requests .Session ()
440
+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
406
441
407
442
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
408
443
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
409
444
410
- response = requests .get (src_url , stream = True )
445
+ response = session .get (src_url , timeout = 30 , stream = True )
411
446
response .raise_for_status ()
412
447
pdf_bytes = response .content
413
448
0 commit comments