I am trying to convert an uploaded Docx file to pdf in Django using the docx2pdf module.But when I pass the file into the convert function I am getting the following error,
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
My views.py:
def post(self, request):
files=request.FILES.getlist("files")
for f in files:
file_type=getFileType(f)[-1]
final_pdf=f
file_type == ".docx":
new_file= File()
fs = FileSystemStorage()
file_name = fs.save(f.name, f)
uploaded_file_url = fs.url(file_name)
convert('media/'+f.name)
new_file.file.save(f.name.split(".")[0]+".pdf",f,save=False)
new_file.save()
resp={"message": "Files Uploaded"}
return Response(resp, status=status.HTTP_200_OK)
Thanks in advance.