D
D
Dmitry Matveev2018-09-13 14:37:50
Django
Dmitry Matveev, 2018-09-13 14:37:50

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.
5b9a49da0c437379005918.png
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.
5b9a4adbd1d76754012426.png
In the end, it turned out to be CommonMiddleware.
5b9a4b05ba28e000384612.png
Then I tried to find the place that gives the error. And I seem to have found it.
5b9a4b7f42f0d486068711.png
If you put reture response before this block, then everything will work fine.
5b9a4be8b8352026738813.png
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 question

Ask a Question

731 491 924 answers to any question