@@ -112,6 +112,10 @@ def image_blur_func(
112112 import cv2 as cv # type: ignore
113113 import numpy as np
114114 import requests
115+ from requests import adapters
116+
117+ session = requests .Session ()
118+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
115119
116120 ext = ext or ".jpeg"
117121
@@ -121,7 +125,7 @@ def image_blur_func(
121125 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
122126 dst_url = dst_obj_ref_rt_json ["access_urls" ]["write_url" ]
123127
124- response = requests .get (src_url )
128+ response = session .get (src_url , timeout = 30 )
125129 bts = response .content
126130
127131 nparr = np .frombuffer (bts , np .uint8 )
@@ -135,12 +139,13 @@ def image_blur_func(
135139 ext = ext_mappings .get (ext , ext )
136140 content_type = "image/" + ext
137141
138- requests .put (
142+ session .put (
139143 url = dst_url ,
140144 data = bts ,
141145 headers = {
142146 "Content-Type" : content_type ,
143147 },
148+ timeout = 30 ,
144149 )
145150
146151 return dst_obj_ref_rt
@@ -157,13 +162,17 @@ def image_blur_to_bytes_func(
157162 import cv2 as cv # type: ignore
158163 import numpy as np
159164 import requests
165+ from requests import adapters
166+
167+ session = requests .Session ()
168+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
160169
161170 ext = ext or ".jpeg"
162171
163172 src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
164173 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
165174
166- response = requests .get (src_url )
175+ response = session .get (src_url , timeout = 30 )
167176 bts = response .content
168177
169178 nparr = np .frombuffer (bts , np .uint8 )
@@ -193,6 +202,10 @@ def image_resize_func(
193202 import cv2 as cv # type: ignore
194203 import numpy as np
195204 import requests
205+ from requests import adapters
206+
207+ session = requests .Session ()
208+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
196209
197210 ext = ext or ".jpeg"
198211
@@ -202,7 +215,7 @@ def image_resize_func(
202215 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
203216 dst_url = dst_obj_ref_rt_json ["access_urls" ]["write_url" ]
204217
205- response = requests .get (src_url )
218+ response = session .get (src_url , timeout = 30 )
206219 bts = response .content
207220
208221 nparr = np .frombuffer (bts , np .uint8 )
@@ -216,12 +229,13 @@ def image_resize_func(
216229 ext = ext_mappings .get (ext , ext )
217230 content_type = "image/" + ext
218231
219- requests .put (
232+ session .put (
220233 url = dst_url ,
221234 data = bts ,
222235 headers = {
223236 "Content-Type" : content_type ,
224237 },
238+ timeout = 30 ,
225239 )
226240
227241 return dst_obj_ref_rt
@@ -245,13 +259,17 @@ def image_resize_to_bytes_func(
245259 import cv2 as cv # type: ignore
246260 import numpy as np
247261 import requests
262+ from requests import adapters
263+
264+ session = requests .Session ()
265+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
248266
249267 ext = ext or ".jpeg"
250268
251269 src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
252270 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
253271
254- response = requests .get (src_url )
272+ response = session .get (src_url , timeout = 30 )
255273 bts = response .content
256274
257275 nparr = np .frombuffer (bts , np .uint8 )
@@ -280,6 +298,10 @@ def image_normalize_func(
280298 import cv2 as cv # type: ignore
281299 import numpy as np
282300 import requests
301+ from requests import adapters
302+
303+ session = requests .Session ()
304+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
283305
284306 ext = ext or ".jpeg"
285307
@@ -296,7 +318,7 @@ def image_normalize_func(
296318 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
297319 dst_url = dst_obj_ref_rt_json ["access_urls" ]["write_url" ]
298320
299- response = requests .get (src_url )
321+ response = session .get (src_url , timeout = 30 )
300322 bts = response .content
301323
302324 nparr = np .frombuffer (bts , np .uint8 )
@@ -312,12 +334,13 @@ def image_normalize_func(
312334 ext = ext_mappings .get (ext , ext )
313335 content_type = "image/" + ext
314336
315- requests .put (
337+ session .put (
316338 url = dst_url ,
317339 data = bts ,
318340 headers = {
319341 "Content-Type" : content_type ,
320342 },
343+ timeout = 30 ,
321344 )
322345
323346 return dst_obj_ref_rt
@@ -336,6 +359,10 @@ def image_normalize_to_bytes_func(
336359 import cv2 as cv # type: ignore
337360 import numpy as np
338361 import requests
362+ from requests import adapters
363+
364+ session = requests .Session ()
365+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
339366
340367 ext = ext or ".jpeg"
341368
@@ -349,7 +376,7 @@ def image_normalize_to_bytes_func(
349376 src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
350377 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
351378
352- response = requests .get (src_url )
379+ response = session .get (src_url , timeout = 30 )
353380 bts = response .content
354381
355382 nparr = np .frombuffer (bts , np .uint8 )
@@ -374,11 +401,15 @@ def pdf_extract_func(src_obj_ref_rt: str) -> str:
374401
375402 from pypdf import PdfReader # type: ignore
376403 import requests
404+ from requests import adapters
405+
406+ session = requests .Session ()
407+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
377408
378409 src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
379410 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
380411
381- response = requests .get (src_url , stream = True )
412+ response = session .get (src_url , timeout = 30 , stream = True )
382413 response .raise_for_status ()
383414 pdf_bytes = response .content
384415
@@ -403,11 +434,15 @@ def pdf_chunk_func(src_obj_ref_rt: str, chunk_size: int, overlap_size: int) -> s
403434
404435 from pypdf import PdfReader # type: ignore
405436 import requests
437+ from requests import adapters
438+
439+ session = requests .Session ()
440+ session .mount ("https://" , adapters .HTTPAdapter (max_retries = 3 ))
406441
407442 src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
408443 src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
409444
410- response = requests .get (src_url , stream = True )
445+ response = session .get (src_url , timeout = 30 , stream = True )
411446 response .raise_for_status ()
412447 pdf_bytes = response .content
413448
0 commit comments