Search code examples
pythondjangopython-3.xherokupython-requests

Connection broken: IncompleteRead(0 bytes read) when sending request to Django on Heroku


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!


Solution

  • Found the problem, it was because 1 of my GET requests has a body and it messed things up.