Problem passing JSON long format parameters to Matlab Production Server
9 views (last 30 days)
Show older comments
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 Comments
Answers (3)
Kojiro Saito
on 18 Jan 2018
Edited: Kojiro Saito
on 18 Jan 2018
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 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!