У меня есть загрузчик файлов asyn c, использующий Dropzone. js и все работает нормально, за исключением странной ошибки сервера, которая время от времени появляется, когда я отменяю запрос на загрузку. Ошибка несовместима, иногда я получаю ожидаемый результат после отмены запроса на загрузку, а в других случаях ошибка отображается в идентичных условиях.
Обратите внимание, что я использую регулирование сети chrome поэтому я могу отменить загрузку до ее завершения.
Это представление загрузки файла:
@login_required
def media_upload(request):
if request.method == 'POST' and request.FILES.getlist('media'):
file = request.FILES.getlist('media')[0]
fs = FileSystemStorage()
try:
img = Image.open(file)
img.verify()
except Exception as exp:
return HttpResponse(exp, status=400)
# Converting and saving media
img = Image.open(file)
media_prefix = ('evnt_u' + str(request.user.id))
media_ext = '.jpg'
if img.format != 'JPEG':
img = img.convert('RGB')
buffer01 = BytesIO()
img.save(buffer01, format='JPEG')
file = InMemoryUploadedFile(
buffer01, None, (media_prefix+media_ext), 'image/jpeg', buffer01.tell, None)
media = fs.save((media_prefix+media_ext), file)
return HttpResponse(media, status=200)
else:
return HttpResponse(status=400)
Я правильно получаю POST /media/upload/ HTTP/1.1" 400 0
с кодом выше, но это не соответствует. в другой раз я получаю соответствующий ответ, за которым следует цепочка необученных исключений:
Bad Request: /fa/media/upload/
[05/Apr/2020 18:36:51] "POST /fa/media/upload/ HTTP/1.1" 400 0
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 453, in _write
result = self.stdout.write(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 796, in write
self._sock.sendall(b)
OSError: [Errno 41] Protocol wrong type for socket
[05/Apr/2020 18:36:51] "POST /fa/media/upload/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49199)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 453, in _write
result = self.stdout.write(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 796, in write
self._sock.sendall(b)
OSError: [Errno 41] Protocol wrong type for socket
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/Volumes/Storage/WorkSpace/Projects/envs/meetup_dev/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 86, in handle_error
super().handle_error()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 717, in __init__
self.handle()
File "/Volumes/Storage/WorkSpace/Projects/envs/meetup_dev/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 154, in handle
handler.run(self.server.get_app())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 144, in run
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------