nodes: 0, module; 1, function_definition; 2, function_name:call_validator_api; 3, parameters; 4, block; 5, identifier:dsn; 6, identifier:api_data; 7, expression_statement; 8, expression_statement; 9, try_statement; 10, if_statement; 11, expression_statement; 12, return_statement; 13, comment:"""
      Single call to the lipd.net validator API
  
      'api_data' format:
       [
          {"type": "csv", "filenameFull": /path/to/filename.csv, "data": "", ...},
          {"type": "json", "filenameFull": /path/to/metadata.jsonld, "data": "", ...},
          ...
      ]
      Result format:
          {"dat": <dict>, "feedback": <dict>, "filename": "", "status": ""}
  
      :param str dsn: Dataset name
      :param list api_data: Prepared payload for one LiPD dataset. All the sorted files (txt, jsonld, csv), API formatted
      :return list result: Validator result for one file
      """; 14, assignment; 15, comment:# Contact server and send LiPD metadata as the payload; 16, comment:# print("Sending request to LiPD.net validator...\n"); 17, block; 18, except_clause; 19, except_clause; 20, except_clause; 21, not_operator; 22, block; 23, assignment; 24, identifier:result; 25, identifier:_filename; 26, binary_operator:dsn + ".lpd"; 27, expression_statement; 28, comment:# The payload that is going to be sent with the JSON request; 29, expression_statement; 30, comment:# Development Link; 31, comment:# response = requests.post('http://localhost:3000/api/validator', data=payload); 32, comment:# Production Link; 33, expression_statement; 34, if_statement; 35, as_pattern; 36, block; 37, as_pattern; 38, block; 39, as_pattern; 40, block; 41, identifier:result; 42, expression_statement; 43, subscript; 44, identifier:_filename; 45, identifier:dsn; 46, string:".lpd"; 47, assignment; 48, assignment; 49, assignment; 50, comparison_operator:response.status_code == 413; 51, block; 52, elif_clause; 53, elif_clause; 54, comment:# For an example of the JSON Response, reference the "sample_data_response" below; 55, comment:# Convert JSON string into a Python dictionary; 56, comment:# print("Converting response to json...\n"); 57, else_clause; 58, identifier:TypeError; 59, as_pattern_target; 60, expression_statement; 61, expression_statement; 62, attribute; 63, as_pattern_target; 64, expression_statement; 65, expression_statement; 66, identifier:Exception; 67, as_pattern_target; 68, expression_statement; 69, expression_statement; 70, assignment; 71, identifier:result; 72, string:"filename"; 73, identifier:api_data; 74, call; 75, identifier:payload; 76, dictionary; 77, identifier:response; 78, call; 79, attribute; 80, integer:413; 81, expression_statement; 82, comparison_operator:response.status_code == 404; 83, block; 84, comparison_operator:response.status_code == 400; 85, block; 86, block; 87, identifier:e; 88, call; 89, assignment; 90, attribute; 91, identifier:ConnectionError; 92, identifier:e; 93, call; 94, assignment; 95, identifier:e; 96, call; 97, assignment; 98, identifier:result; 99, dictionary; 100, attribute; 101, argument_list; 102, pair; 103, pair; 104, attribute; 105, argument_list; 106, identifier:response; 107, identifier:status_code; 108, assignment; 109, attribute; 110, integer:404; 111, expression_statement; 112, attribute; 113, integer:400; 114, expression_statement; 115, expression_statement; 116, attribute; 117, argument_list; 118, identifier:result; 119, dictionary; 120, identifier:requests; 121, identifier:exceptions; 122, attribute; 123, argument_list; 124, identifier:result; 125, dictionary; 126, attribute; 127, argument_list; 128, identifier:result; 129, dictionary; 130, pair; 131, pair; 132, pair; 133, pair; 134, identifier:json; 135, identifier:dumps; 136, identifier:api_data; 137, string; 138, identifier:api_data; 139, string; 140, string; 141, identifier:requests; 142, identifier:post; 143, string; 144, keyword_argument; 145, identifier:result; 146, dictionary; 147, identifier:response; 148, identifier:status_code; 149, assignment; 150, identifier:response; 151, identifier:status_code; 152, assignment; 153, assignment; 154, identifier:logger_validator_api; 155, identifier:warning; 156, call; 157, pair; 158, pair; 159, pair; 160, pair; 161, identifier:logger_validator_api; 162, identifier:warning; 163, call; 164, pair; 165, pair; 166, pair; 167, pair; 168, identifier:logger_validator_api; 169, identifier:debug; 170, call; 171, pair; 172, pair; 173, pair; 174, pair; 175, string:"dat"; 176, dictionary; 177, string:"feedback"; 178, dictionary; 179, string:"filename"; 180, identifier:_filename; 181, string:"status"; 182, string:"EMPTY RESPONSE"; 183, string_content:json_payload; 184, string_content:apikey; 185, string_content:lipd_linked; 186, string_content:http://www.lipd.net/api/validator; 187, identifier:data; 188, identifier:payload; 189, pair; 190, pair; 191, pair; 192, pair; 193, identifier:result; 194, dictionary; 195, identifier:result; 196, dictionary; 197, identifier:result; 198, call; 199, attribute; 200, argument_list; 201, string:"dat"; 202, dictionary; 203, string:"feedback"; 204, dictionary; 205, string:"filename"; 206, identifier:_filename; 207, string:"status"; 208, string:"JSON DECODE ERROR"; 209, attribute; 210, argument_list; 211, string:"dat"; 212, dictionary; 213, string:"feedback"; 214, dictionary; 215, string:"filename"; 216, identifier:_filename; 217, string:"status"; 218, string:"UNABLE TO REACH SERVER"; 219, attribute; 220, argument_list; 221, string:"dat"; 222, dictionary; 223, string:"feedback"; 224, dictionary; 225, string:"filename"; 226, identifier:_filename; 227, string:"status"; 228, call; 229, string:"dat"; 230, dictionary; 231, string:"feedback"; 232, dictionary; 233, string:"filename"; 234, identifier:_filename; 235, string:"status"; 236, string:"HTTP 413: Request Entity Too Large"; 237, pair; 238, pair; 239, pair; 240, pair; 241, pair; 242, pair; 243, pair; 244, pair; 245, attribute; 246, argument_list; 247, string:"get_validator_results: TypeError: {}"; 248, identifier:format; 249, identifier:e; 250, string:"get_validator_results: ConnectionError: {}"; 251, identifier:format; 252, identifier:e; 253, string:"get_validator_results: Exception: {}"; 254, identifier:format; 255, identifier:e; 256, attribute; 257, argument_list; 258, string:"dat"; 259, dictionary; 260, string:"feedback"; 261, dictionary; 262, string:"filename"; 263, identifier:_filename; 264, string:"status"; 265, string:"HTTP 404: Not Found"; 266, string:"dat"; 267, dictionary; 268, string:"feedback"; 269, dictionary; 270, string:"filename"; 271, identifier:_filename; 272, string:"status"; 273, attribute; 274, identifier:json; 275, identifier:loads; 276, attribute; 277, string:"ERROR BEFORE VALIDATION, {}"; 278, identifier:format; 279, identifier:e; 280, identifier:response; 281, identifier:text; 282, identifier:response; 283, identifier:text
code: def call_validator_api(dsn, api_data):
      """
      Single call to the lipd.net validator API
  
      'api_data' format:
       [
          {"type": "csv", "filenameFull": /path/to/filename.csv, "data": "", ...},
          {"type": "json", "filenameFull": /path/to/metadata.jsonld, "data": "", ...},
          ...
      ]
      Result format:
          {"dat": <dict>, "feedback": <dict>, "filename": "", "status": ""}
  
      :param str dsn: Dataset name
      :param list api_data: Prepared payload for one LiPD dataset. All the sorted files (txt, jsonld, csv), API formatted
      :return list result: Validator result for one file
      """
      _filename = dsn + ".lpd"
  
      try:
          # Contact server and send LiPD metadata as the payload
          # print("Sending request to LiPD.net validator...\n")
          api_data = json.dumps(api_data)
  
          # The payload that is going to be sent with the JSON request
          payload = {'json_payload': api_data, 'apikey': 'lipd_linked'}
  
          # Development Link
          # response = requests.post('http://localhost:3000/api/validator', data=payload)
  
          # Production Link
          response = requests.post('http://www.lipd.net/api/validator', data=payload)
  
          if response.status_code == 413:
              result = {"dat": {}, "feedback": {}, "filename": _filename,
                        "status": "HTTP 413: Request Entity Too Large"}
          elif response.status_code == 404:
              result = {"dat": {}, "feedback": {}, "filename": _filename,
                        "status": "HTTP 404: Not Found"}
          elif response.status_code == 400:
              result = {"dat": {}, "feedback": {}, "filename": _filename,
                        "status": response.text}
  
          # For an example of the JSON Response, reference the "sample_data_response" below
  
          # Convert JSON string into a Python dictionary
          # print("Converting response to json...\n")
          else:
              result = json.loads(response.text)
  
      except TypeError as e:
          logger_validator_api.warning("get_validator_results: TypeError: {}".format(e))
          result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "JSON DECODE ERROR"}
      except requests.exceptions.ConnectionError as e:
          logger_validator_api.warning("get_validator_results: ConnectionError: {}".format(e))
          result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "UNABLE TO REACH SERVER"}
      except Exception as e:
          logger_validator_api.debug("get_validator_results: Exception: {}".format(e))
          result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "ERROR BEFORE VALIDATION, {}".format(e)}
      if not result:
          result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "EMPTY RESPONSE"}
  
      result["filename"] = _filename
      return result