@@ -22,18 +22,28 @@ async def sem_task(task):
2222
2323 return await asyncio .gather (* [sem_task (task ) for task in tasks ])
2424
25+ async def read_response (response ):
26+ message = await response .content .read ()
27+ jsonMessage = json .loads (message )
28+ print (jsonMessage )
29+
2530async def send_request (session , url , json ):
2631 headers = {
2732 "Authorization" : f"Bearer { sesame_api_token } " ,
2833 "Content-Type" : "application/json; charset=utf-8" ,
2934 }
3035
3136 try :
37+
3238 async with session .post (url , json = json , headers = headers ) as response :
33- response .raise_for_status () # Raises error for 4xx/5xx responses
3439 print (f"Request to { url } successful: { response .status } " )
40+ await read_response (response )
41+ response .raise_for_status () # Raises error for 4xx/5xx responses
42+ except aiohttp .ClientResponseError as e :
43+ # This catches responses like 400, 404, 500 etc.
44+ print (f"Request to { url } failed with status { e .status } : { e .message } " )
3545 except aiohttp .ClientError as e :
36- print (f"Request to { url } failed: { e } " )
46+ print (f"Request to { url } failed: { str ( e ) } " )
3747 except asyncio .TimeoutError :
3848 print (f"Request to { url } timed out" )
3949
0 commit comments