Open openfly opened 7 years ago
It's basically choosing the wrong content-type and passing data in the wrong format.
@openfly it is possible to capture the real HTTP request sent? It's hard to understand why your Java service returned an HTTP/415.
As a side note could you add in the execution trace that you posted what each line represents?
I cleaned it up a little but the key bits are that the content-type is wrong. it changed to 'Content-Type': 'application/x-www-form-urlencoded'
which triggers the 415. If i manually go into _request_options and change the header it fixes that 415... but still gets a 400 from how it handles the data it's passing as formData. It's not being passed to requests correctly. it shouldn't be being urlencoded ( I believe ).
You're not setting the (optional) attachment parameter, which is of type file
. Currently we don't explicitly set the content type, but let the HTTP client take care of it in case of file uploads. Check out the relevant source code in bravado-core.
application/x-www-form-urlencoded
is the more efficient encoding unless you need to send non-text data; I'm wondering why your Java server is so strict about it. Anyway, it does seem like we're not fully respecting the spec in this case. This would need to be fixed both in the Fido and the requests client.
Yeah that's a bug man.
multi-part form is handled differently than x-www-form-urlencoded for stuff other than file uploads. so if the api expects multi-part form and you hand it x-www-form-urlencoded you will see failures to parse.
basically bravado is failing to set the method appropriately based on the swagger spec.
I can't really speak for the actions of the java server... beyond it doing what it's doing. =/
I'll take a look and see if I have the up front knowledge to fix it without breaking more than I fix.
So this is more a bug with requests than bravado.
https://github.com/requests/requests/issues/1081 <-- requests maintainer basically refuses to support multipart format correctly because he doesn't like how it changes the python module.
https://franklingu.github.io/programming/2017/10/30/post-multipart-form-data-using-requests/ <-- may be a work around... ie setting a None for the file attachment, when none is presented.
http://toolbelt.readthedocs.io/en/latest/uploading-data.html#streaming-multipart-data-encoder the toolbelt has a much more robust solution to the issue.
Been a while but ended up revisiting my work around for this in my code. And I had more info on the issue to add here.
can't seem to convince the methods to adhere to content-type multipart/form-data
spec for endpoint looks roughly like this:
the example code looks roughly like:
execution looks kinda like this ( with some debug prints ):