flask-restful: Bad Request on GET with header Content-Type
I have a simple GET request on an endpoint returning a list of entity.
This query gives me back a 400 Bad request error :
curl -s -D - http://localhost:5000/workdays -H 'Content-Type: application/json'
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json
Content-Length: 98
Date: Wed, 30 Sep 2015 20:13:44 GMT
{
"message": "The browser (or proxy) sent a request that this server could not understand."
}
If I remove the Content-Type header, there is no error. Is it not overkill to reject a GET request with a content type header ?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 31 (11 by maintainers)
IMO since
GET
s should not have a body, the headerContent-Type
can be safely ignored.I’ve created a middleware to do so:
I’m leaning towards the following:
Content-Type
headers. HTTP Spec never says thatContent-Type
must not be included on bodyless requests.Still have this issue and I request to open this and fix this.
Admittedly, if
location
is set to'args'
the request doesn’t blow up:I will use this as a short term fix. I’ve been thinking about moving the parsing over to webargs anyways.
@phillip-martin
location='args'
seems to be the solution.In that case, I’d completely expect Restful to pitch a fit because there isn’t a JSON body included with the GET request (and there never should be either). So, the issue isn’t really sending a GET with a Content-Type, it’s attempting to parse an non-existent content body.
I ran into this with requests when working on an API at work, ultimately it comes down to the fact that JSON libraries in Python don’t seem to be okay with
''
(meaning, no content) as a JSON body. I’m actually unsure if''
is considered valid JSON or not (I’d have to dig through the RFC to be 100%).Has anyone else experienced this since it was closed? I was able to reproduce this on a fresh install of Python 2.7.10 Restful 0.3.5 and Flask 0.10.1.
Testing:
It all goes wrong on this line -
parser.parse_args()
. #556 is the same issue. Just to be safe I attempted the same with the latest master. Same thing.