1

I have followed this tutorial exactly and I am running into a conenction error:

https://www.knowru.com/blog/how-create-restful-api-for-machine-learning-credit-model-in-r/

I run the following code:

library(plumber)
r <- plumb("deploy_ml_credit_model.R")
r$run(host = "127.0.0.1", port = 3582, swagger = FALSE)

The I go to the terminal in R and run

curl -X POST -d '{"Status.of.existing.checking.account": "A11", "Duration.in.month": 24, "Credit.history": "A32", "Savings.account.bonds": "A63"}' -H 'Content-Type: application/json' 127.0.0.1:3582

I obtain the following error:

C:\Users\USER\Desktop\creditdata>curl -X POST -d '{"Status.of.existing.checking.account": "A11", "Duration.in.month":
 24, "Credit.history": "A32", "Savings.account.bonds": "A63"}' -H 'Content-Type: application/json' 127.0.0.1:3582
curl: (6) Could not resolve host: A11,
curl: (6) Could not resolve host: Duration.in.month
curl: (6) Could not resolve host: 24,
curl: (6) Could not resolve host: Credit.history
curl: (6) Could not resolve host: A32,
curl: (6) Could not resolve host: Savings.account.bonds
curl: (3) [globbing] unmatched close brace/bracket in column 4
curl: (6) Could not resolve host: application
{"error":["404 - Resource Not Found"]}

I have looked for a solution online and I cannot seem to find a way around this.

I go to http://localhost:3582/ and I see {"error":["404 - Resource Not Found"]}

When I set swagger = TRUE I can go to 127.0.0.1:3582/__swagger__/ and see a web page but cannot input data etc.

I also tried to connect using Python:

import requests
import json
response = requests.post(
    “localhost:3582”
    , headers={“Content-Type”: “application/json”}
    , data=json.dumps({
        "Status.of.existing.checking.account": "A11"
    , "Duration.in.month": 24
    , "Credit.history": "A32"
    , "Savings.account.bonds": "A63"
    })
)

print response.json()

And I obtained the following error:

File "<ipython-input-12-84b178a53d7e>", line 4
    “localhost:3582”
             ^
SyntaxError: invalid character in identifier

I have tried a number of different combinations to the 127.0.0.1 line. Replacing with localhost, changing to different ports, setting it directly to 127.0.0.1:3582/__swagger__/predict etc. All returning an error.

user113156
  • 6,761
  • 5
  • 35
  • 81
  • For `requesets.post`, use `requests.post("http://ocalhost:3582", ...)`. See: https://stackoverflow.com/questions/25582875/set-port-in-requests. Your `curl` command looks like you are using unix style string escaping. I think windows uses quotes differently. Maybe this will help: https://stackoverflow.com/a/15262019/2372064 – MrFlick Mar 06 '19 at 17:21
  • I tried your suggestions and typing in `C:\WINDOWS\system32>curl http://localhost:3582/` into command promt gives the following error `{"error":["404 - Resource Not Found"]}` – user113156 Mar 06 '19 at 17:46
  • Do you actually have an endpoint set up for the root? It looks like the server is working from that response. – MrFlick Mar 06 '19 at 17:59
  • Sorry, I don´t fully understand your last response. I get to the point where `> r <- plumb("deploy_ml_credit_model.R") > r$run(host = "127.0.0.1", port = 3582, swagger = FALSE) Starting server to listen on port 3582` and then I head over to `http://localhost:3582/` and this is where I get the `error 404`. – user113156 Mar 06 '19 at 18:06

0 Answers0