Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why seldon chose application/x-www-form-urlencoded as Content-Type instead of application/json when treating predict requests? #935

Closed
cloga opened this issue Oct 10, 2019 · 7 comments

Comments

@cloga
Copy link

cloga commented Oct 10, 2019

I just find seldon use application/x-www-form-urlencoded instead of application/json, this make me confused, in my opinion , I should use json as data for both input and out datatype.

What pros and cons when treating ml predict requests using application/x-www-form-urlencoded and application/json?

I find some discussion about this:https://stackoverflow.com/questions/11281117/x-www-form-urlencoded-vs-json-http-post

If the structure of encoded data is guaranteed to be a flat list of name-value pairs, x-www-form-urlencoded seems sufficient. If the structure could be (arbitrarily) complex (e.g. nesting lists or associative arrays), then definitely use JSON.

@ukclivecox
Copy link
Contributor

We have both.

@RequestMapping(value = "/api/v0.1/predictions", method = RequestMethod.POST, consumes = "application/json; charset=utf-8", produces = "application/json; charset=utf-8")

Please reopen if I misinterpreted you.

@cloga
Copy link
Author

cloga commented Oct 11, 2019

Thanks @cliveseldon ,How can I post data to predict interface use application/json?
I find the example using application/x-www-form-urlencoded:

!curl -d 'json={"data":{"ndarray":[[1,2,3]]}}' http://0.0.0.0:5000/predict

And in the microservice/microservice.py file in the seldonio/seldon-core-s2i-python3 image, I find this (line 47 - 55):

def extract_message():
    jStr = request.form.get("json")
    if jStr:
        message = json.loads(jStr)
    else:
        raise SeldonMicroserviceException("Empty json parameter in data")
    if message is None:
        raise SeldonMicroserviceException("Invalid Data Format")
    return message

It means if user post data not in the form data which key is json server will raise empty json parameter error.

Is there any example about how to post data with application/json?

@ukclivecox
Copy link
Contributor

ukclivecox commented Oct 11, 2019

You can use POST as well:
e.g.

curl  0.0.0.0:5000/predict -H "Content-Type: application/json"  -d '{"data":{"ndarray":[[1,2]]}}'

@ukclivecox
Copy link
Contributor

Which version of Seldon are you using. This has changed.

message = request.get_json()

@axsaucedo
Copy link
Contributor

@blublinsky I think this is what you had been talking about in regards to the form/json ^

@cloga
Copy link
Author

cloga commented Oct 11, 2019

image

I use seldonio/seldon-core-s2i-python3 to build model server image, and find extract_message method in microservice/microservice.py

but now I can't find extract_message method in project:
image

also can't find the Empty json parameter in data excpetion:

image

I check the seldon_core module code on my desktop, it is the new verison, which didn't have extract_message method in microservice.py

image

but when I dig into the image build from seldonio/seldon-core-s2i-python3 I find extract_message method in microservice/microservice.py

image

@eminemence
Copy link

This is what worked for me:
curl -v -s http://localhost:5000/predict -H "Content-Type: application/x-www-form-urlencoded" -d "json={\"data\":{\"ndarray\":[[123,123,123]]}}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants