'422 Error when using httr for uploading data to batchPrediction API (data robot)

Disclaimer:
This error is related to a subscription-based tool and hence the issue is likely not going to be reproducible for any reader. Nevertheless, any suggestions on http request might still help me debug the issue faced.

Objective:
I am trying to upload a CSV dataset to DataRobot's batch prediction API, having deployed a model for it.

Context and issue:

  • DataRobot requires 2 requests to be made in order to upload a CSV dataset for scoring by the deployed model: a POST request, and a PUT request
  • I am able to send a POST request successfully
  • However, sending the PUT request returns a Client error(402): Unprocessable entity (RFC4918)
  • Specifically, the error states Detected 263 extra values in row 3 than the no. of columns in header. Could be due to improperly quoted values or wrong encoding
  • I checked the CSV format and the CSV intake settings (default) at the API end point - all of them match
  • I even tried uploading the same CSV file manually via GUI - it works seamlessly...

Possible clues to solution?

  • I kept ~10 rows with only 3 columns (original dataset has 200+) and tried uploading. This led to a successful upload although the subsequent scoring did not take place given missing columns.
  • I feel maybe I am incorrectly specifying my PUT request, so any guidance is much appreciated!
library(httr)
post_req <- POST(batch_api_url, 
add_headers(.headers = c(Authorization = "Bearer xxxxxx")), 
body = list(deploymentID = ID, passthroughColumnsSet = "all"), 
verbose())
# Works...

put_req <- PUT(batch_api_url, 
add_headers(.headers = c(Authorization = "Bearer xxxxxx",
"content-type" = "text/csv; encoding=utf-8", 
"content-size" = filesize)),
body = list(input_file = upload_file(filepath, "text/csv"), to_json = F),
encode = "multipart", verbose())
# 422 error if I use all 200+ columns; but succeeds in uploading if I use a reduced dataset (3-4 columns only)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source