AbiWord:[文件路径/测试]不是有效的文件名?

问题描述

致力于将文档从 docx,doc转换为pdf 。了解 Abiword ,它可以将文档从一种文件格式转换为另一种文件格式。将python与os模块一起使用,该模块应该执行我的命令。这可以正常工作,没有空格文件,但是只要有个带有空格的文件,就会出现此错误。试图打印命令并检查它是对还是错,但是命令是正确的。

def saveDocx(files,user):
destination = Path.joinpath(MEDIA_ROOT,user,"trash")
current_doc_files = list()
for file in files:
    fs = FileSystemStorage(location=destination)
    filename = fs.save(file.name,file)
    filename = os.path.join(destination,filename)
    current_doc_files.append(filename)
print("doc files---->",current_doc_files)
return current_doc_files,destination

def convToPdf(current_doc_files,user):
    current_pdf_files = list()
    for file in current_doc_files:
        cmd = "abiword --to=pdf {}".format(file)
        print("----cmd----",cmd)
        try:
            os.system(cmd)
            pdf_file_name = os.path.splitext(file)[0] + '.pdf'
            print("converted ",pdf_file_name)
            current_pdf_files.append(pdf_file_name)
        except Exception as ex:
            print("--------Exception--------")
            print(ex)
    return current_pdf_files

在pythonanywhere上创建Web应用程序,他们提供了Abiword文字处理器。看一下输出 文件没有空格

doc files----> ['/home/trash/test.docx']
**2020-11-08 06:10:20 ----cmd---- abiword --to=pdf /home/trash/test.docx**
2020-11-08 06:10:21 Failed to connect to Mir: Failed to connect to server socket: No such file or directory
2020-11-08 06:10:21 Unable to init server: Could not connect: Connection refused
2020-11-08 06:10:21 #012** (abiword:12): WARNING **: clutter Failed 0,get a life.
2020-11-08 06:10:21 Failed to connect to Mir: Failed to connect to server socket: No such file or directory
2020-11-08 06:10:21 Unable to init server: Could not connect: Connection refused
2020-11-08 06:10:21 #012(abiword:12): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' Failed
**2020-11-08 06:10:21 converted  /home/trash/test.pdf**

图片中包含空格的文件时,出现以下错误

doc files----> ['/home/trash/test test.docx']
**2020-11-08 05:46:50 ----cmd---- abiword --to=pdf /home/test test.docx**
2020-11-08 05:46:50 Failed to connect to Mir: Failed to connect to server socket: No such file or directory
2020-11-08 05:46:50 Unable to init server: Could not connect: Connection refused
2020-11-08 05:46:50 #012** (abiword:10): WARNING **: clutter Failed 0,get a life.
2020-11-08 05:46:50 Failed to connect to Mir: Failed to connect to server socket: No such file or directory
2020-11-08 05:46:50 Unable to init server: Could not connect: Connection refused
**2020-11-08 05:46:50 AbiWord: [/home/trash/test] is not a valid file name.**

我有另一种解决方案,用下划线替换空格,但想知道这是怎么回事。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)