When hosting Flask app on Windows 2022 server with 64bit Python, using libraries flask, docxtpl and docx2pdf, I am getting and error
pywintypes.com_error: (-2147024891, 'Access is denied.', None, None)
It looks like that the Flask app can't access Word. I gave all permissions to all users to Python folder, flask app folder and office folder that has the word.exe in it.
How can I give the permissions correctly so the docx2pdf python library can access word.
I include
from flask import Flask, render_template, request
from docxtpl import DocxTemplate
from docx2pdf import convert
import pythoncom
And this is how I convert
docx_path = os.path.abspath('document_new.docx')
convert(docx_path, "output.pdf", pythoncom.CoInitialize())
Error:
File "C:\web\app.py", line 112, in handle_form_submission
word = win32.DispatchEx("Word.Application")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\web\env\Lib\site-packages\win32com\client\__init__.py", line 145, in DispatchEx dispatch = pythoncom.CoCreateInstanceEx(^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147024891, 'Access is denied.', None, None)
I gave all permissions to all users to Python folder, flask app folder and office folder that has the word.exe in it.
It works normally on localhost, but not on Windows 2022 server. Apart from docx2pdf, everything works fine.