首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用python请求将pmml模型放入开放取心

如何使用python请求将pmml模型放入开放取心
EN

Stack Overflow用户
提问于 2014-10-30 02:10:28
回答 2查看 531关注 0票数 0

我正在尝试使用python请求将.pmml模型放置到本地开放中心服务器。

这起作用(来自包含DecisionTreeIris.pmml的目录):

代码语言:javascript
复制
curl -X PUT --data-binary @DecisionTreeIris.pmml -H "Content-type: text/xml" http://localhost:8080/openscoring/model/DecisionTreeIris

这并不是:

代码语言:javascript
复制
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

返回:

代码语言:javascript
复制
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'

我也试过:

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

返回:

代码语言:javascript
复制
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名代表的人应该考虑制作一个“开放”标签。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-30 21:10:46

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

代码语言:javascript
复制
r = requests.put('http://localhost:8080/openscoring/model/DecisionTreeIris', data=open(file, 'rb'), headers={'Content-type': 'text/xml', 'Accept': 'text/xml'})
票数 0
EN

Stack Overflow用户

发布于 2014-10-30 11:47:53

您应该检查方法org.openscoring.service.ModelResource#deploy(String, HttpServletRequest)的注释,以获得有效的请求/响应MIME类型。

第一个请求失败,因为服务器只接受application/xmltext/xml有效负载。第二个请求失败,因为服务器发出application/json有效负载,但客户端只愿意接受text/xml有效负载。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26643903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档