Reputation: 375
Working on document conversion from docx, doc to pdf. Get to know about Abiword which can convert documents from one file format to others. Using python with the os module which supposes to execute my command. This is working properly files with no spaces files but whenever there is a file with spaces it is giving this error. Tried to print command and checked is it right or wrong, But the command is right.
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
creating web app on pythonanywhere, They have provided Abiword word processor. Have a look to output on When a file with no space
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**
When a file with spaces comes in the picture, gives error as below
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.**
I have alternate solution replacing spaces with an underscore but want to know what is wrong with this.
Upvotes: 0
Views: 545