@@ -229,39 +229,34 @@ class AIOHttpSession(aiohttp.ClientSession):
229229 RETRY_LIMIT = 3
230230 BACKOFF_FACTOR = 0.3
231231
232- class AIOHttpSession (aiohttp .ClientSession ):
233- RETRY_STATUS_CODES = [401 , 403 , 502 , 503 , 504 ]
234- RETRY_LIMIT = 3
235- BACKOFF_FACTOR = 0.3
236-
237- @staticmethod
238- def _copy_form_data (data : aiohttp .FormData ) -> aiohttp .FormData :
239- form_data = aiohttp .FormData (quote_fields = False )
240- for field in data ._fields : # noqa
241- if isinstance (field [2 ], io .IOBase ):
242- field [2 ].seek (0 )
243- form_data .add_field (
244- value = field [2 ],
245- content_type = field [1 ].get ("Content-Type" , "" ),
246- ** field [0 ],
247- )
248- return form_data
232+ @staticmethod
233+ def _copy_form_data (data : aiohttp .FormData ) -> aiohttp .FormData :
234+ form_data = aiohttp .FormData (quote_fields = False )
235+ for field in data ._fields : # noqa
236+ if isinstance (field [2 ], io .IOBase ):
237+ field [2 ].seek (0 )
238+ form_data .add_field (
239+ value = field [2 ],
240+ content_type = field [1 ].get ("Content-Type" , "" ),
241+ ** field [0 ],
242+ )
243+ return form_data
249244
250- async def request (self , * args , ** kwargs ) -> aiohttp .ClientResponse :
251- attempts = self .RETRY_LIMIT
252- delay = 0
253- for _ in range (attempts ):
254- delay += self .BACKOFF_FACTOR
255- try :
256- response = await super ()._request (* args , ** kwargs )
257- if attempts <= 1 or response .status not in self .RETRY_STATUS_CODES :
258- return response
259- except (aiohttp .ClientError , RuntimeError ) as e :
260- if attempts <= 1 :
261- raise
262- if isinstance (e , RuntimeError ):
263- data = kwargs ["data" ]
264- if isinstance (data , aiohttp .FormData ):
265- kwargs ["data" ] = self ._copy_form_data (data )
266- attempts -= 1
267- await asyncio .sleep (delay )
245+ async def request (self , * args , ** kwargs ) -> aiohttp .ClientResponse :
246+ attempts = self .RETRY_LIMIT
247+ delay = 0
248+ for _ in range (attempts ):
249+ delay += self .BACKOFF_FACTOR
250+ try :
251+ response = await super ()._request (* args , ** kwargs )
252+ if attempts <= 1 or response .status not in self .RETRY_STATUS_CODES :
253+ return response
254+ except (aiohttp .ClientError , RuntimeError ) as e :
255+ if attempts <= 1 :
256+ raise
257+ if isinstance (e , RuntimeError ):
258+ data = kwargs ["data" ]
259+ if isinstance (data , aiohttp .FormData ):
260+ kwargs ["data" ] = self ._copy_form_data (data )
261+ attempts -= 1
262+ await asyncio .sleep (delay )
0 commit comments