librelist archives

« back to archive

400 error, nulls in request.data

400 error, nulls in request.data

From:
Jason Corbett
Date:
2013-12-06 @ 19:05
I am having an interesting issue.  Whenever a particular client posts to my
flask app, it get's a 400 before it even gets to my code.  When I added
some logging (@app.after_request) detailing the request and the data I see
nulls in the request JSON.

This is a rewrite of my app, and the previous version in Java, with the
same post data, has no problem.  Is there something I can do to clean the
data on the server side?

Here are the logs if it helps (the ^@ is how vim shows the nulls):
[12/06/13 11:26:28 AM|   DEBUG|access]: POST /api/testruns = 400
(in:application/json,out:text/html)
[12/06/13 11:26:28 AM|   DEBUG|access]: Request Data:

{"build":{"buildId":"52a207fabdb40d60ed07f4e2","name":"5"},"config":{"configId":"52a0fd511d92ee0a5a3cc142","filename":null,"name":"Test
Environment"},"dateCreated":1386354389695,"id":null,"name":"Build
Acceptance Tests -

MSSQL","project":{"id":"52a0f6461d92ee09ce01bf81","name":"FTK"},"release":{"name":"5.2.0","releaseId":"52a207fabdb40d60ed07f4e1"},"runFinished":-62135571600000,"runStarted":-62135571600000,"runtimeOptions":null,"state":"TO_BE_RUN","testplanId":"52a20815bdb40d60ed07f4e3"}^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
[12/06/13 11:26:28 AM|   DEBUG|access]: Headers:
EnvironHeaders([('Content-Length', u'932'), ('Host', u'10.10.7.143:8080'),
('Expect', u'100-continue'), ('Content-Type', u'application/json')])


Jason

Re: [flask] 400 error, nulls in request.data

From:
gioi
Date:
2013-12-11 @ 13:45
Il 06/12/2013 20:05, Jason Corbett ha scritto:
> I am having an interesting issue.  Whenever a particular client posts
> to my flask app, it get's a 400 before it even gets to my code.
How can you be sure? Have you wrapped your code with a try-except block?

Re: [flask] 400 error, nulls in request.data

From:
Jason Corbett
Date:
2013-12-11 @ 16:12
Well the first statement never finished.  I found the problem.  It blew up
in request.get_json() causing the 400 error.  I wrote my own function to do
what get_json does.  It uses request.data, strips out the nulls, and then
uses json.loads to get the data.  I've got it working.  Thanks for the help.

Jason Corbett


On Wed, Dec 11, 2013 at 6:45 AM, gioi <g@gioi.tk> wrote:

> Il 06/12/2013 20:05, Jason Corbett ha scritto:
> > I am having an interesting issue.  Whenever a particular client posts
> > to my flask app, it get's a 400 before it even gets to my code.
> How can you be sure? Have you wrapped your code with a try-except block?
>
>

Re: [flask] 400 error, nulls in request.data

From:
gioi
Date:
2013-12-11 @ 16:25
Il 11/12/2013 17:12, Jason Corbett ha scritto:
> Well the first statement never finished.  I found the problem.  It
> blew up in request.get_json() causing the 400 error.  I wrote my own
> function to do what get_json does.  It uses request.data, strips out
> the nulls, and then uses json.loads to get the data.  I've got it
> working.  Thanks for the help.
Oh - I think the solution is simply write valid json!

Re: [flask] 400 error, nulls in request.data

From:
Jason Corbett
Date:
2013-12-11 @ 17:10
Yeah, I know.  The client is a bit out of my control.

Jason


On Wed, Dec 11, 2013 at 9:25 AM, gioi <g@gioi.tk> wrote:

> Il 11/12/2013 17:12, Jason Corbett ha scritto:
> > Well the first statement never finished.  I found the problem.  It
> > blew up in request.get_json() causing the 400 error.  I wrote my own
> > function to do what get_json does.  It uses request.data, strips out
> > the nulls, and then uses json.loads to get the data.  I've got it
> > working.  Thanks for the help.
> Oh - I think the solution is simply write valid json!
>
>