@@ -402,7 +402,14 @@ def _process_append_requests_local(
402402 ):
403403 def get_files (batch ):
404404 request_payload = [
405- (ITEMS_KEY , (None , json .dumps (batch ), "application/json" ))
405+ (
406+ ITEMS_KEY ,
407+ (
408+ None ,
409+ json .dumps (batch , allow_nan = False ),
410+ "application/json" ,
411+ ),
412+ )
406413 ]
407414 for item in batch :
408415 image = open ( # pylint: disable=R1732
@@ -426,7 +433,8 @@ def get_files(batch):
426433 files_per_request .append (get_files (batch ))
427434 payload_items .append (batch )
428435
429- responses = asyncio .run (
436+ loop = asyncio .get_event_loop ()
437+ responses = loop .run_until_complete (
430438 self .make_many_files_requests_asynchronously (
431439 files_per_request ,
432440 f"dataset/{ dataset_id } /append" ,
@@ -476,7 +484,7 @@ async def _make_files_request(
476484 """
477485 Makes an async post request with files to a Nucleus endpoint.
478486
479- :param files: A list of tuples (filename, file_pointer, file_type)
487+ :param files: A list of tuples (name, ( filename, file_pointer, file_type) )
480488 :param route: route for the request
481489 :param session: Session to use for post.
482490 :return: response
@@ -502,12 +510,21 @@ async def _make_files_request(
502510 timeout = DEFAULT_NETWORK_TIMEOUT_SEC ,
503511 ) as response :
504512 logger .info ("API request has response code %s" , response .status )
513+
514+ try :
515+ data = await response .json ()
516+ except aiohttp .client_exceptions .ContentTypeError :
517+ # In case of 404, the server returns text
518+ data = await response .text ()
519+
505520 if not response .ok :
506521 self .handle_bad_response (
507- endpoint , session .post , aiohttp_response = response
522+ endpoint ,
523+ session .post ,
524+ aiohttp_response = (response .status , response .reason , data ),
508525 )
509526
510- return await response . json ()
527+ return data
511528
512529 def _process_append_requests (
513530 self ,
0 commit comments