У меня есть модель, к которой я пытаюсь подключиться в R. Я открываю модель, запустив;
> library(plumber)
> r <- plumb("deploy_ml_credit_model.R")
Warning message:
In readLines(file) :
incomplete final line found on 'deploy_ml_credit_model.R'
> r$run(swagger = FALSE)
Starting server to listen on port 3582
Затем я перехожу на Python и запускаю следующее:
Код Python:
import requests
import json
response = requests.post(
“http://127.0.0.1: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-41-507692393845>", line 4
“http://127.0.0.1:3582”
^
SyntaxError: invalid character in identifier
Я открываю ссылку в браузере и получаю это сообщение: {"error":["404 - Resource Not Found"]}
Куда я пойду не так? У меня plumber
работает в фоновом режиме в RStudio, поэтому он должен подключиться. У меня есть проблемы с разрешениями или брандмауэром?
EDIT:
Я все еще получаю следующее сообщение, когда набираю http://127.0.0.1:3582/predict
- ошибка http://127.0.0.1:3582/predict
. Я очищаю код и получаю следующую ошибку:
Код 2:
import requests
import json
response = requests.post(
"http://127.0.0.1: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()
Ошибка 2:
File "<ipython-input-49-0669c2ac9d9d>", line 15
print response.json()
^
SyntaxError: invalid syntax
РЕДАКТИРОВАТЬ 3:
Я печатаю:
print (response)
и я получаю эту ошибку:
<Response [404]>
Но модель R работает в фоновом режиме
EDIT:
Использование:
curl -X POST "http://127.0.0.1:8000/__swagger__/predict" -d '{"Status.of.existing.checking.account": "A11", "Duration.in.month": 24, "Credit.history": "A32", "Savings.account.bonds": "A63"}' -H "accept: application/json"
выдает эту ошибку:
curl -X POST "http://127.0.0.1:8000/__swagger__/predic
t" -d '{"Status.of.existing.checking.account": "A11", "Duration.in.month": 24, "Credit.history":
"A32", "Savings.account.bonds": "A63"}' -H "accept: application/json"
<h1>Bad Request</h1>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
EDIT:
Я запускаю эту строку:
curl POST -H 'Content-Type:accept:application/json' -d "{/"Credit.history/":/"A32/"}" http://127.0.0.1:8000/__swagger__/predict
Поэтому я решил удалить большую часть того, что я хочу отправить в модель, до одной переменной, и теперь я получаю эту ошибку:
curl POST -H 'Content-Type:accept:application/json' -d "{/"Credit.history/":/"A32/"}" http://127.0.0.1:8000/__swagger__/predict
curl: (6) Could not resolve host: POST
{"error":["500 - Internal server error"],"message":["Error: lexical error: invalid char in json text.\n {/Credit.history/:/A32/}\n
(right here) ------^\n\n"]}