0

我正在尝试使用 python 请求将 .pmml 模型放入本地开放评分服务器。
这有效(来自包含 DecisionTreeIris.pmml 的目录):

curl -X PUT --data-binary @DecisionTreeIris.pmml -H "Content-type: text/xml" http://localhost:8080/openscoring/model/DecisionTreeIris

这不会:

import requests
file = '/Users/weitzenfeld/IntelliJProjects/openscoring/openscoring-server/etc/DecisionTreeIris.pmml'
r = requests.put('http://localhost:8080/openscoring/model/DecisionTreeIris', files={'file': open(file, 'rb')})
r.text

返回:

u'<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>\n<title>Error 415 </title>\n</head>\n<body>\n<h2>HTTP ERROR: 415</h2>\n<p>Problem accessing /openscoring/model/DecisionTreeIris. Reason:\n<pre>    Unsupported Media Type</pre></p>\n<hr /><i><small>Powered by Jetty://</small></i>\n</body>\n</html>\n'

我也试过:

r = requests.put('http://localhost:8080/openscoring/model/DecisionTreeIris', files={'file': open(file, 'rb')}, headers={'Content-type': 'text/xml', 'Accept': 'text/xml'})
r.text

返回:

u'<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>\n<title>Error 406 </title>\n</head>\n<body>\n<h2>HTTP ERROR: 406</h2>\n<p>Problem accessing /openscoring/model/DecisionTreeIris. Reason:\n<pre>    Not Acceptable</pre></p>\n<hr /><i><small>Powered by Jetty://</small></i>\n</body>\n</html>\n'

请注意,我的 python 尝试与此问题的公认答案相同:Using Python to PUT PMML

此外,具有 >1500 代表的人应该考虑制作一个“开放评分”标签。

4

2 回答 2

0

You should check the annotations of the method org.openscoring.service.ModelResource#deploy(String, HttpServletRequest) for valid request/response MIME types.

The first request fails because the server only accepts application/xml and text/xml payloads. The second request fails, because the server emits application/json payloads, but your client is only willing to accept text/xml payloads.

于 2014-10-30T11:47:53.810 回答
0

解决方案是放置数据,而不是文件处理程序:

r = requests.put('http://localhost:8080/openscoring/model/DecisionTreeIris', data=open(file, 'rb'), headers={'Content-type': 'text/xml', 'Accept': 'text/xml'})
于 2015-01-30T21:10:46.813 回答