Answer the question
In order to leave comments, you need to log in
Django connection drops due to CommonMiddleware?
Hello, I've run into a very strange problem. I do unloading from 1C. And I noticed that sometimes for some reason the file is not uploaded to the Django server. started digging, put Charly to view the packets sent. And saw that Djnago closes the connection.
Because of this, of course, it is impossible to work with these files.
I started digging into what could be the problem. Played with DATA_UPLOAD_MAX_MEMORY_SIZE and did len(request.body). Nothing helped, randomly Django closed the connection. Firewall turned off too. I was given the idea to turn off Middleware gradually. And lo and behold, everything started to go.
In the end, it turned out to be CommonMiddleware.
Then I tried to find the place that gives the error. And I seem to have found it.
If you put reture response before this block, then everything will work fine.
But why exactly because of this place there is a blackout, I don’t understand. Breakpoint did not help, it passes through them and closes the connection. Please help, I don't know what to do anymore. Thank you!
view code:
class Exchange(View):
def get(self, request):
request_type = request.GET['type']
request_mode = request.GET['mode']
if request_type in ('catalog', 'sale') and request_mode == 'checkauth':
response = HttpResponse()
response.write('success\n')
response.write('sessionid\n')
response.write('123456789')
return response
if request_type in ('catalog', 'sale') and request_mode == 'init':
response = HttpResponse()
response.write('zip=no\n')
response.write(f'file_limit={settings.DATA_UPLOAD_MAX_MEMORY_SIZE}')
return response
if request_type == 'catalog' and request_mode == 'import':
return HttpResponse('success')
return HttpResponse('failure')
def post(self, request):
len(request.body)
return HttpResponse('success')
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question