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.