none
Web service deployment on model published in Azure ML gallery does not work RRS feed

  • Question

  • I am looking at 6B of 6 on the Retail forecasting model.

    https://gallery.azure.ai/Experiment/bef6f84ac80d4625891f9f0ae768b356

    I keep getting error 400 when I tried to deploy the web service.

    Please help. (It looks like I cannot upload my data file which is a CSV file)

    Thanks a million,

    Fred

    ------------------------------------------------

    $error$details[[1]]$message

    [1] "No request body provided or error in deserializing the request body."

    code is as follows:(Please note that I removed the API key here because I am not sure if I should make it public, but I got a valid API key)

                

    rm()
    library("RCurl")
    library("rjson")

    # Accept SSL certificates issued by public Certificate Authorities
    options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

    h = basicTextGatherer()
    hdr = basicHeaderGatherer()
    data<-read.csv("C:/EDX_R/Forecasting- Cleaned Input.csv")


    req = list(

      Inputs = list(


        "input1" = list(
        "ColumnNames" = list("ID1", "ID2", "time", "value"),
         ### "Values" = list( list( "0", "0", "", "0" ),  list( "0", "0", "", "0" )  )
          "Values" =  apply(data,1,as.list)
        )                ),
      GlobalParameters = setNames(fromJSON('{}'), character(0))
    )

    body = enc2utf8(toJSON(req))
    api_key = "MyAPIKeyHere" # Replace this with the API key for the web service
    authz_hdr = paste('Bearer', api_key, sep=' ')

    h$reset()
    curlPerform(url = "https://ussouthcentral.services.azureml.net/workspaces/ae24c20fadf145f58c9547b6ee5591a9/services/3919963c0a114ef4aa551aef25f5c483/execute?api-version=2.0&details=true",
                httpheader=c('Content-Type' = "application/json", 'Authorization' = authz_hdr),
                postfields=body,
                writefunction = h$update,
                headerfunction = hdr$update,
                verbose = TRUE
    )

    headers = hdr$value()
    httpStatus = headers["status"]
    if (httpStatus >= 400)
    {
      print(paste("The request failed with status code:", httpStatus, sep=" "))

      # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
      print(headers)
    }

    print("Result:")
    result = h$value()
    print(fromJSON(result))

    ---------------------below is output on console--------------

    > rm()
    > library("RCurl")
    > library("rjson")
    > 
    > # Accept SSL certificates issued by public Certificate Authorities
    > options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
    > 
    > h = basicTextGatherer()
    > hdr = basicHeaderGatherer()
    > data<-read.csv("C:/EDX_R/Forecasting- Cleaned Input.csv")
    > 
    > 
    > req = list(
    +   
    +   Inputs = list(
    +     
    +     
    +     "input1" = list(
    +     "ColumnNames" = list("ID1", "ID2", "time", "value"),
    +      ### "Values" = list( list( "0", "0", "", "0" ),  list( "0", "0", "", "0" )  )
    +       "Values" =  apply(data,1,as.list)
    +     )                ),
    +   GlobalParameters = setNames(fromJSON('{}'), character(0))
    + )
    > 
    > body = enc2utf8(toJSON(req))
    > api_key = "CtYQBv5nmGw6epVwthf9Q54tcS/SB432SAScYAIH0c8UX1+rwlwfzGtI/iDryrUYyqUhfcyBCfnR5yUysn0Wrw==" # Replace this with the API key for the web service
    > authz_hdr = paste('Bearer', api_key, sep=' ')
    > 
    > h$reset()
    > curlPerform(url = "https://ussouthcentral.services.azureml.net/workspaces/ae24c20fadf145f58c9547b6ee5591a9/services/3919963c0a114ef4aa551aef25f5c483/execute?api-version=2.0&details=true",
    +             httpheader=c('Content-Type' = "application/json", 'Authorization' = authz_hdr),
    +             postfields=body,
    +             writefunction = h$update,
    +             headerfunction = hdr$update,
    +             verbose = TRUE
    + )
    *   Trying 13.85.87.118...
    * Connected to ussouthcentral.services.azureml.net (13.85.87.118) port 443 (#0)
    * successfully set certificate verify locations:
    *   CAfile: C:/Users/FL/Documents/R/win-library/3.4/RCurl/CurlSSL/cacert.pem
      CApath: none
    * SSL connection using TLSv1.0 / ECDHE-RSA-AES256-SHA
    * Server certificate:
    *        subject: CN=ussouthcentral.services.azureml.net
    *        start date: 2018-06-20 19:10:54 GMT
    *        expire date: 2020-06-20 19:10:54 GMT
    *        subjectAltName: ussouthcentral.services.azureml.net matched
    *        issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT TLS CA 1
    *        SSL certificate verify ok.
    > POST /workspaces/ae24c20fadf145f58c9547b6ee5591a9/services/3919963c0a114ef4aa551aef25f5c483/execute?api-version=2.0&details=true HTTP/1.1
    Host: ussouthcentral.services.azureml.net
    Accept: */*
    Content-Type: application/json
    Authorization: Bearer MyAPIKeyHere
    Content-Length: 153502
    Expect: 100-continue
    < HTTP/1.1 100 Continue
    < HTTP/1.1 400 Bad Request
    < Content-Length: 194
    < Content-Type: application/json; charset=utf-8
    < ETag: "7e57425f38b24212aeeda17668b99416"
    < Server: Microsoft-HTTPAPI/2.0
    < x-ms-request-id: 6e79e8ae-bfb4-4054-98cd-af09926f9007
    < Date: Tue, 17 Sep 2019 00:55:05 GMT
    * HTTP error before end of send, stop sending
    < 
    * Closing connection 0
    OK 
     0 
    > 
    > headers = hdr$value()
    > httpStatus = headers["status"]
    > if (httpStatus >= 400)
    + {
    +   print(paste("The request failed with status code:", httpStatus, sep=" "))
    +   
    +   # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
    +   print(headers)
    + }
    [1] "The request failed with status code: 400"
                            Content-Length                           Content-Type 
                                     "194"      "application/json; charset=utf-8" 
                                      ETag                                 Server 
    "\"7e57425f38b24212aeeda17668b99416\""                "Microsoft-HTTPAPI/2.0" 
                           x-ms-request-id                                   Date 
    "6e79e8ae-bfb4-4054-98cd-af09926f9007"        "Tue, 17 Sep 2019 00:55:05 GMT" 
                                    status                          statusMessage 
                                     "400"                          "Bad Request" 
    > 
    > print("Result:")
    [1] "Result:"
    > result = h$value()
    > print(fromJSON(result))
    $error
    $error$code
    [1] "BadArgument"
    $error$message
    [1] "Invalid argument provided."
    $error$details
    $error$details[[1]]
    $error$details[[1]]$code
    [1] "RequestBodyInvalid"
    $error$details[[1]]$message
    [1] "No request body provided or error in deserializing the request body."


    FL

    Tuesday, September 17, 2019 1:11 AM

All replies

  • Hello,

    This error is returned when the JSON is not correctly formatted as a string. This could be a similar issue as seen by this user. Could you please try to use JSON.stringify() to convert data value to a JSON string?

    Also it would be great if you can try sample data first before trying to read the entire CSV as an input.

    -Rohit

    Wednesday, September 18, 2019 10:37 AM
    Moderator
  • Hi Rohit, Thank you for your reply. The R code that converts my list to JSON is the following.

    body = enc2utf8(toJSON(req))

    It looks to me that JSON.stringify() is Javascript. But I am running R. So, when I used JSON.stringify(), I just got an error right away.

    Error in JSON.stringify(req) : could not find function "JSON.stringify"

    Please advise.

    Thanks,

    Fred


    FL

    Wednesday, September 18, 2019 6:17 PM
  • My question is actually very simple. I have a dataframe a number of rows and four columns.

    How do I get a list of lists (of the rows) to put in "values" in the request body as follows.

    ----------------------------------------------

                      

    req = list(

       Inputs = list(
         "input1" = list(
         "ColumnNames" = list("ID1", "ID2", "time", "value"),
         "Values" = list( list( "0", "0", "", "0" ),  list( "0", "0", "", "0" )  )

         )                ),
       GlobalParameters = setNames(fromJSON('{}'), character(0))
     )

    --------------------------------------

    Thanks in advance.


    FL

    Sunday, September 22, 2019 2:48 AM