Problem passing JSON long format parameters to Matlab Production Server
9 次查看(过去 30 天)
显示 更早的评论
I am using MATLAB production server to run functions via REST API. I have a function with 5 input parameters. When I pass parameters using JSON small format (e.g. 5 double) using POST/synchronous method then function returns my result fine. This is my Python code:
conn = http.client.HTTPConnection("serverURL:9910")
headers = { "Content-Type": "application/json"}
body = json.dumps({ "nargout": 1, "rhs" : ['run', inputs] })
conn.request("POST", "/optimFctExample/model", body, headers)
response = conn.getresponse()
If
inputs = [1,2,3,4,5]
then it accepts the rhs just fine. However, I would like to pass more complex parameters than double, and I understand I need to use JSON large format for this.
I tested using
input= [{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [1]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [2]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [3]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [4]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [5]
}]
but then the server returns a 400 error of type:
Error while parsing request:
[err] [worker:31] Expected a data inside special float objects to be a string
What am I doing wrong? is it the way I encaplustae the JSON long format? If I try to pass the original long format lhs (I got from GET) to the rhs, then it works, so the problem is not with the inputs call itself, but rather with the rhs format here. Thanks for your help.
0 个评论
回答(3 个)
Kojiro Saito
2018-1-18
编辑:Kojiro Saito
2018-1-18
Instead of mixing small and large JSON formats, please put 'run' parameter to large JSON. The following will work.
input= [{
"mwtype": "char",
"mwsize": [1,3],
"mwdata": ["run"]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [1]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [2]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [3]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [4]
},{
"mwtype": "double",
"mwsize": [1,1],
"mwdata": [5]
}]
body = json.dumps({ "nargout": 1, "rhs" : inputs })
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!