【问题标题】:How to use python requests to PUT a pmml model to openscoring如何使用 python 请求将 pmml 模型放入 openscoring
【发布时间】:2015-01-31 05:10:46
【问题描述】:

我正在尝试使用 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 的人应该考虑制作一个“开放评分”标签。

【问题讨论】:

    标签: python-requests pmml


    【解决方案1】:

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

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

    【讨论】:

    • 我已经检查了注释,并阅读了请求文档,但我仍然没有弄清楚。
    • 在第二次尝试中,将标题更改为以下内容:headers={'Content-type': 'text/xml', 'Accept': 'application/json'}。
    • 错误 400:错误请求
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-02-24
      • 2018-05-03
      • 2019-02-22
      • 2019-06-05
      • 2016-12-23
      • 2019-11-24
      • 2019-06-23
      • 1970-01-01
      • 2022-01-25
      相关资源
      最近更新 更多