Я работаю над приложением Django, в котором я хочу создать несколько асинхронных запросов с ajax на сервер django.Он работает нормально, если есть менее 5 асинхронных запросов, но если есть больше запросов django return 500 (Internal Server Error)
для некоторых запросов.Если я делаю синхронные запросы AJAX, он работает нормально.
Код, куда я отправляю несколько запросов ajax:
for (i=2; i <= lastIndex; i++){
pidForm['page_index'] = i;
$.ajax({
type: 'POST',
url: '{% url "search_by_pid" %}',
data: pidForm,
success: function (data) {
console.log(data);
$(data.api_response.bugs).each(function(index, bugs){
var id = bugs.id;
createInnerHtml(id);
});
}
})
}
Мое представление django, куда я отправляю запрос ajax:
def get_bug_by_pid(request):
product_id_form = ProductIdForm()
if request.method == 'GET':
return render(request, 'search_bug_by_pid.html',
{'page_title': 'ProductID', 'product_id_form': product_id_form})
elif request.method == 'POST':
product_id = request.POST['product_id']
if 'page_index' in request.POST:
api_call = ApiCall()
page_index = request.POST['page_index']
api_response = api_call.bug_api_call_by_pid(product_id, page_index)
return JsonResponse({'api_response': api_response,'product_id': product_id})
Internal Server Error: /pid/
Traceback (most recent call last):
File "C:\exception.py", line 34, in inner
response = get_response(request)
File "C:\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\views.py", line 26, in get_bug_by_pid
api_response = api_call.bug_api_call_by_pid(product_id, page_index)
File "api_calls.py", line 33, in bug_api_call_by_pid
return json.loads(r.content)
File "C:\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Любая идея, как можноЯ решаю проблему или что я делаю не так?