我正在尝试使用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名代表的人应该考虑制作一个“开放”标签。
发布于 2015-01-30 21:10:46
解决方案是放置数据,而不是文件处理程序:
r = requests.put('http://localhost:8080/openscoring/model/DecisionTreeIris', data=open(file, 'rb'), headers={'Content-type': 'text/xml', 'Accept': 'text/xml'})发布于 2014-10-30 11:47:53
您应该检查方法org.openscoring.service.ModelResource#deploy(String, HttpServletRequest)的注释,以获得有效的请求/响应MIME类型。
第一个请求失败,因为服务器只接受application/xml和text/xml有效负载。第二个请求失败,因为服务器发出application/json有效负载,但客户端只愿意接受text/xml有效负载。
https://stackoverflow.com/questions/26643903
复制相似问题