このチュートリアルに正確に従っていますが、接続エラーが発生しています。
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__/
とWebページは見れるがデータ入力などはできない
また、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
など、すべてエラーを返します。