@@ -245,24 +245,28 @@ async def _request(self, *, http_verb, api_url, req_args):
245245 Returns:
246246 A dictionary of the response data.
247247 """
248+ session = None
248249 if self .session and not self .session .closed :
249- async with self .session .request (http_verb , api_url , ** req_args ) as res :
250- return {
251- "data" : await res .json (),
252- "headers" : res .headers ,
253- "status_code" : res .status ,
254- }
255- async with aiohttp .ClientSession (
256- loop = self ._event_loop ,
257- timeout = aiohttp .ClientTimeout (total = self .timeout ),
258- auth = req_args .pop ("auth" ),
259- ) as session :
260- async with session .request (http_verb , api_url , ** req_args ) as res :
261- return {
262- "data" : await res .json (),
263- "headers" : res .headers ,
264- "status_code" : res .status ,
265- }
250+ session = self .session
251+ else :
252+ session = aiohttp .ClientSession (
253+ timeout = aiohttp .ClientTimeout (total = self .timeout ),
254+ auth = req_args .pop ("auth" , None ),
255+ )
256+
257+ response = None
258+ async with session .request (http_verb , api_url , ** req_args ) as res :
259+ data = {}
260+ try :
261+ data = await res .json ()
262+ except aiohttp .ContentTypeError :
263+ self ._logger .debug (
264+ f"No response data returned from the following API call: { api_url } ."
265+ )
266+ response = {"data" : data , "headers" : res .headers , "status_code" : res .status }
267+
268+ await session .close ()
269+ return response
266270
267271 @staticmethod
268272 def _get_user_agent ():
0 commit comments