我完全遵循了本教程,并且遇到对接错误:
https://www.knowru.com/blog/how-create-restful-api-for-machine-learning-credit-model-in-r/
我运行以下代码:
library(plumber)
r <- plumb("deploy_ml_credit_model.R")
r$run(host = "127.0.0.1", port = 3582, swagger = FALSE)
我去R的终端并运行
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
我收到以下错误:
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"]}
我一直在网上寻找解决方案,但似乎找不到解决方法。
我去http://localhost:3582/,看到{"error":["404 - Resource Not Found"]}
设置swagger = TRUE
后,我可以转到127.0.0.1:3582/__swagger__/
并查看网页,但无法输入数据等。
我也尝试使用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()
我得到了以下错误:
File "<ipython-input-12-84b178a53d7e>", line 4
“localhost:3582”
^
SyntaxError: invalid character in identifier
我在127.0.0.1
行中尝试了多种不同的组合。替换为localhost
,更改为其他端口,将其直接设置为127.0.0.1:3582/__swagger__/predict
等。所有返回错误。