Info: I want to upload files using Uppy in frontend and django-tus as backend for file processing. I am getting error TypeError: exceptions must derive from BaseException
.
Traceback
Internal Server Error: /tus/upload/6393bfe5-277e-4c68-b9af-c0394be796b9
Traceback (most recent call last):
File "/django_tus/tusfile.py", line 75, in get_tusfile_or_404
raise TusResponse(status=404)
TypeError: exceptions must derive from BaseException
[06/Aug/2022 14:36:42] "HEAD /tus/upload/6393bfe5-277e-4c68-b9af-c0394be796b9 HTTP/1.1" 500 103054
[06/Aug/2022 14:36:42,624] - Broken pipe from ('127.0.0.1', 35814)
[06/Aug/2022 14:36:42] "POST /tus/upload/ HTTP/1.1" 201 0
[06/Aug/2022 14:36:42] "PATCH /tus/upload/8295bef4-c94a-4ab7-9c75-2635c74428d8 HTTP/1.1" 204 0
https://github.com/alican/django-tus/blob/master/django_tus/tusfile.py
class TusUpload(View):
def head(self, request, resource_id):
tus_file = TusFile.get_tusfile_or_404(str(resource_id))
return TusResponse(
status=200,
extra_headers={
'Upload-Offset': tus_file.offset,
'Upload-Length': tus_file.file_size,
})
def create_initial_file(metadata, file_size: int):
resource_id = str(uuid.uuid4())
cache.add("tus-uploads/{}/filename".format(resource_id), "{}".format(metadata.get("filename")), settings.TUS_TIMEOUT)
cache.add("tus-uploads/{}/file_size".format(resource_id), file_size, settings.TUS_TIMEOUT)
cache.add("tus-uploads/{}/offset".format(resource_id), 0, settings.TUS_TIMEOUT)
cache.add("tus-uploads/{}/metadata".format(resource_id), metadata, settings.TUS_TIMEOUT)
tus_file = TusFile(resource_id)
tus_file.write_init_file()
return tus_file
EDIT: Our pull request has now fixed this error.
The django-tus attempts in case of 404 error raise in line 60 TusResponse
which does not however inherit from exception.
This is an error of the library. It has not been updated in 2 years and according to the @torek BaseException
inheritance was not previously enforced. You could try to wrap it in try-except with TypeError
but in my implementation this does not work.
You could attempt to add BaseException
to inherited classes of TusResponse
in your version of django-tus.
class TusResponse(HttpResponse, BaseException):
which should remove the error.