Reputation: 553
I have a front-end server that is getting some JSON data from my backend server. Both servers are running Django. This is the exact code that gets the json data..
def View(request):
r = requests.get(path)
return HttpResponse(r.json())
However, I am running into a strange problem today where the call completes successfully ONCE after restarting the server. If I run the following code: -
def View(request):
r = requests.get(path)
r = requests.get(path)
return HttpResponse(r.json())
This works successfully as well.
However, on the second time that View() is called, I get an error. This is what the error message says:
"uWSGI exceptions catcher for "GET /api/v1/backend/" (request plugin: "python", modifier1: 0)
Exception: TypeError: http header value must be a string
Exception class: TypeError
Exception message: http header value must be a string"
Clearly, the error is being thrown on my backend server, but I only changed some templates on the frontend today. I am at a loss as to what has caused this problem to start occurring today. Can anyone point me in the right direction?
Upvotes: 1
Views: 237
Reputation: 11396
give it the right json header:
return HttpResponse(data, content_type='application/json')
Upvotes: 4