所以我正在制作一个烧瓶网络应用程序,并且我添加了一个 docx 到 pdf 转换器,但是即使它很简单,每次我遇到问题时它都无法正常工作,所以我使用这个 python 包将 docx 转换为 pdf https://pypi .org/project/docx2pdf/直到我在烧瓶中上传文件并开始转换。转换时出现错误
这是我的代码
@app.route("/pdf", methods=["POST"])
def pdf2docx_post():
file = request.files['file']
if file and allowed_file(file.filename):
filename = file.filename
file.save(secure_filename(filename))
convert(filename, filename.split('.')[0] + '.docx')
convert(filename, "output.pdf")
convert(filename)
return send_file("output.pdf", as_attachment=True)
return render_template("pdf.html", wait="Pleas wait your download will start automatically")
我得到这个错误
Traceback (most recent call last):
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\flask\app.py", line 2091, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\flask\app.py", line 2076, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\flask\app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\flask\app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\app\main.py", line 145, in pdf2docx_post
convert(filename, filename.split('.')[0] + '.docx')
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\docx2pdf\__init__.py", line 102, in convert
paths = resolve_paths(input_path, output_path)
File "C:\Users\UwU\OneDrive\Desktop\UwU web\Web Development\all-in-one-tools\tools-web\Lib\site-packages\docx2pdf\__init__.py", line 94, in resolve_paths
assert str(output_path).endswith(".pdf")
AssertionError
提前致谢
注意:我已经使用了许多 StackOVERFLOW 答案,但没有奏效