Reputation: 101
I have a view that returns a JsonResponse in Django
def some_view(request):
return JsonResponse({'a': 1, 'b': 2})
And somewhere else in side the same project, I have a piece of code that sends a GET request to the url corresponds to that view:
import requests
def client_func():
requests.get(url_to_some_views)
It works on my local machine but after deploying to heroku, sometimes I get the error: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))
After some testing, I found out that there is an extra field in the response header of some_view
: transfer-encoding: chunked
so I guess it might be what caused the problem but I'm still not sure how to handle this. So far I have tried to add stream=True
to the get call in client_func
but the problem still persists.
Can someone help me with that might be the cause of my problem and to solve this please. Thank you very much!
Upvotes: 5
Views: 8154
Reputation: 3118
This was the first place I landed while on a desperate Google search for "IncompleteRead django", because I was getting incomplete JSON responses from my Django application. So while my problem is not related to the original question, it has enough symptomatic overlap that I think it's appropriate to give my solution here.
It turns out that either Django or NGINX was trying to use temporary files to store a very large JSON response. The server hard drive was full, however, and so the temporary file creation was failing. This apparently does not stop the response process, and so I was getting an incomplete JSON as a response, with a total length much lower than what was expected.
Freeing up space on the host machine solved the issue.
Of special note is that making a raw request with the Python requests library did not indicate anything about "IncompleteRead", but trying to call .json()
on the request object failed because the JSON was invalid (due to the truncation)
Upvotes: 0
Reputation: 101
Found the problem, it was because 1 of my GET requests has a body and it messed things up.
Upvotes: 3