1

I have a RESTful API programmed in Flask and am making requests using Kenneth Reitz requests project. For a particular route I want to POST binary data along with some additional headers to describe the data. The REST API looks at the headers for the POST and if there are problems with these header values, a 412 status code is returned along with some JSON content to describe the issue.

The problem I am having if the data content is above a certain size they JSON content does not come back through requests.

# This works
>>> r=requests.post(url, headers=headers, allow_redirects=False, data=data[:3400])
>>> r.status_code
412
>>> r.content
'{\n  "code": 412, \n  "context": "Header xyz is invalid", \n  "message": "RESOURCE_INVALID"\n}

 # The request content disappears here, same data, same url, same headers
 >>> r=requests.post(url, headers=headers, allow_redirects=False, data=data[:3500])
 >>> r.status_code
 412
 >>> r.content
 ''

I followed this request through the guts of Flask and the constructed response looks fine, it has the JSON content, so I believe that the issue lies somewhere in the guts of requests but haven't been able to track down exactly where.

Has anyone seen this particular problem when posting large amounts of data to a RESTful API?

Paul Joireman
  • 2,689
  • 5
  • 25
  • 33
  • Ultimately traced this to a uwsgi problem as described in this post: http://stackoverflow.com/questions/3970495/nginx-connection-reset-response-from-uwsgi-lost/5114508#5114508 – Paul Joireman Nov 17 '15 at 16:59
  • Another useful post describing this: http://stackoverflow.com/questions/14053670/no-response-with-post-request-and-content-type-application-json-in-flask – Paul Joireman Nov 17 '15 at 17:00

0 Answers0