Python docx2pdf Convert Com_Error - python

I want to convert 2 docx files (which are in same path) in same code.
Yesterday it was working. But today i have an error. Still it's working, it convert files but it stop the code on that cell '''docx2pdf.convert(path)''' and i have different codes after it, code must continue.
I didn't change anything.
Error is:
**0%| | 0/4 [00:00<?, ?it/s]
Traceback (most recent call last):
File "C:\Users\username\word_automation\example.py", line 372, in convert("C:/Users/username/word_automation/")
File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\docx2pdf_init_.py", line 106, in convert return windows(paths, keep_active)
File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\docx2pdf_init_.py", line 25, in Windows doc = word.Documents.Open(str(docx_filepath))
File "<COMObject >", line 5, in Open
com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Dosya bozuk görünüyor.', 'wdmain11.chm', 25272,-2146822496), None)**
How can i fix this?
Thanks for your help.

-2146822496 is 0x800A16A0, which is "the file appears to be damaged". If you can open this file in Word, try doing a "save as" and replacing the original.

I solved the error.
My program makes new word files from another word files. And one of the new word file left a hidden broken word file which name is $new.docx. And i can't see it even open hidden files.
I searched it and i saw, i should write to cmd attrib -h -r -s /s /d C:\*.* for be appear hidden files. And in programs folder, it appeared.
I deleted it, error fixed.

Related

Problem downloading MEGA files with python

I am trying to download a file from my MEGA account using the following code from the mega.py library of Python:
from mega import Mega
mega = Mega()
m = mega.login('example#example.com', 'example')
file = m.find('example.txt')
m.download(file, 'D:\\Desktop')
However, it is always returning:
Traceback (most recent call last):
File "D:\Programas\aNaconda\lib\shutil.py", line 788, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] The file is already being used by another process: 'C:\\Users\\vrida\\AppData\\Local\\Temp\\megapy_xdste432' -> 'example.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<ipython-input-26-c3f75106fafb>", line 1, in <module>
m.download(file)
File "D:\Programas\aNaconda\lib\site-packages\mega\mega.py", line 564, in download
return self._download_file(file_handle=None,
File "D:\Programas\aNaconda\lib\site-packages\mega\mega.py", line 745, in _download_file
shutil.move(temp_output_file.name, output_path)
File "D:\Programas\aNaconda\lib\shutil.py", line 803, in move
os.unlink(src)
PermissionError: [WinError 32] The file is already being used by another process: 'C:\\Users\\vrida\\AppData\\Local\\Temp\\megapy_example'
Actually when I enter in the folder (C:\Users\vrida\AppData\Local\Temp) I find a temporary file like the one I'm wanting to download but named megapy_example.
I saw that the following site has a discussion to solve the problem:
https://www.reddit.com/r/learnpython/comments/mw6is2/download_file_from_mega_using_megapy/
asking to add the following lines to the code:
try:
m.download(file, 'D:\\Desktop')
except PermissionError:
continue
In my case, the continue command wasn't working so I simply put in the pass command. The code runs, but I don't know if the file is really saved or not.
Could someone please help me? I really need to download the files and save them.
If it doesn't work through the mega.py library, you guys would somehow know how to download from the public link like this by Python:
https://mega.co.nz/#!cSZCELDb!5O57KMVMIgrPiH5fnaefWeNPDqoDWzGbY-sZkdTUdNk
There's a bug in the library, it's not closing the file before moving it. You could fix the bug by editing the source code:
Open the file at D:\Programas\aNaconda\lib\site-packages\mega\mega.py
Goto line 745 where the line shutil.move(temp_output_file.name, output_path) is.
Add temp_output_file.close() right above it.
Save & try again.

How to fix "Unable to load sound" error with Python Playsound Module?

A while ago I made a little project, and I recently thought it would be cool to add some sounds to it as well. So I looked for ways to play sound in Python 3.x, and Playsound was well reviewed. I have it setup like so: I have folder Python Projects and inside that I have Sound Test But when I try to play my audio file (test.wav) it throws the following error:
Traceback (most recent call last):
File "soundtest.py", line 2, in <module>
playsound('test.wav')
File "/Users/rhett/env/lib/python3.7/site-packages/playsound.py", line 67, in _playsoundOSX
raise IOError('Unable to load sound named: ' + sound)
OSError: Unable to load sound named: file:///Users/rhett/Desktop/Python Projects/Sound Test/test.wav
I tried using the direct path, e.g.:
from playsound import playsound
playsound(/Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav)
I received the exact same error:
Traceback (most recent call last):
File "Sound Test/soundtest.py", line 2, in <module>
playsound("/Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav")
File "/Users/rhett/env/lib/python3.7/site-packages/playsound.py", line 67, in _playsoundOSX
raise IOError('Unable to load sound named: ' + sound)
OSError: Unable to load sound named: file:///Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav
I have found where the problem is.
In the python3.7/site-packages/playsound.py file
The developer has not checked for " " spaces in file path, so spaces character in the file path is creating trouble.
A quick fix without changing playsound.py 's code.
replace your folder name
~/Desktop/Python Projects/Sound Test/test.wav with ~/Desktop/PythonProjects/SoundTest/test.wav
(i.e, remove spaces from folder names)
This will fix your error.
This allows it to work...
s_musicfile = "/Users/xxxxxxxxxx/Desktop/play this file.mp3"
s_musicfile = s_musicfile.replace(" ", "%20")
playsound(s_musicfile)
I think this will work try it especially when it is for raspberry :
Python 2:
sudo apt install python-gst-1.0
Python 3:
sudo apt install python3-gst-1.0

raise "pytesseract.pytesseract.TesseractError: (3221225477, '')"

I got the following error when I tried to find out the Chinese words in a picture by python: (By the way, I had already had "chi_sim.traineddata" training file in tessdata directory and got a successful try to find out English sentences in a picture, so this error really confused me.)
*C:\Users\Lenovo\AppData\Local\Programs\Python\Python37-32\python.exe E:/PKU1.3/python_math/set_for_recognition.py
Traceback (most recent call last):
File "E:/PKU1.3/python_math/set_for_recognition.py", line 5, in <module>
text=pytesseract.image_to_string(Image.open('climb_high.jpeg'),lang='chi_sim')
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytesseract\pytesseract.py", line 295, in image_to_string
return run_and_get_output(*args)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytesseract\pytesseract.py", line 203, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytesseract\pytesseract.py", line 179, in run_tesseract
raise TesseractError(status_code, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (3221225477, '')*
I think this problem is TRAINEDDATA that raised.
I used to develop the OCR project with TESSERACT on windows 7.
Now, I change to windows 10. I get this problem.
but, I found this issue is related to your TRAINEDDATA,
If I use TRAINEDDATA that I have trained on windows 7, then it fine without any error message.
Actually since the error code 3221225477 --> 0xC0000005 : ACCESS_VIOLATION means Tesseract has crashed (from here), change a version of Tesseract may help you.
In 4.00 (beta) and 3.02 this problem is occurred, 3.05 is fine (I use Windows 7).
Hope this helps.
I got this error because my UZN file extended beyond the image area. I patched pytesseract.py (print(' '.join(cmd_args)) in run_tesseract()) which was throwing an assertion error.
Please try the below code :
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files/Tesseract-OCR/tesseract.exe'
tessdata_dir_config = '--tessdata-dir "C:/Program Files/Tesseract-OCR/tessdata"'
img = Image.open('images\Capture2.JPG')
text = pytesseract.image_to_string(img, config=tessdata_dir_config)
print(text)

Opening Word from Python, unexpected behaviour

I'm writing a script to parse word document and get certain outputs. I use the following commands for reading the desired document.
import win32com.client as win32
import Tkinter,tkFileDialog
root = Tkinter.Tk()
root.withdraw()
filename = tkFileDialog.askopenfilename() # getting filename through windows explorer
word = win32.Dispatch("Word.Application")
#word.Documents.Open(filename)
The last line which is commented is how I was planning to implement this. But whenever I try to open a file which has a space in it's filename, this fails. In fact I found that if I give word.Documents.Open("C:/Python27/word sample.docm")
This will also fail, but if I use backslash after C: it'll work perfectly.
In short the below commands for opening document will work:
word.Documents.Open("C:\Python27/word sample.docm")
word.Documents.Open(filename) #if filename don't have a space
And the below ones will not work:
word.Documents.Open("C:/Python27/word sample.docm")
word.Documents.Open(filename) #filename have a space in it
Could someone explain what is going wrong here?
This is the error that I'm receiving:
C:\Users\xxx>C:\Python27\python.exe C:\Python27\test.py
Traceback (most recent call last):
File "C:\Python27\test.py", line 10, in <module>
word.Documents.Open("C:/Python27/word sample.docm")
File "<COMObject <unknown>>", line 8, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word'
, u'This file could not be found.\r (C:\\//Python27/word%20sample.docm)', u'
wdmain11.chm', 24654, -2146823114), None)

Python error "IOError: [Errno 2] No such file or directory" but file is there

I am trying to read a csv file and I am getting the error above but the file is there. The line giving the error is
infilequery = file('D:\x88_2.csv','rb')
and I get the error below.
Traceback (most recent call last):
File "C:\Python26\usrapply_onemol2.py", line 14, in
infilequery = file('D:\x88_2.csv','rb')
IOError: [Errno 2] No such file or directory: 'D:\x88_2.csv'
I can put a file from the same directory in its place and python at least sees it. The result of os.listdir("D:") features 'x88_2.csv' and the result of "dir D:\" also includes it. When putting the filename in and allowing python to complete the path and selecting x88_2.csv from the dropdown, I still get the same error. What is up here?
Try
'D:\\x88_2.csv'
The \x88 is interpreted as the character at code point 0x88. Alternatively you could use raw string
r'D:\x88_2.csv'
or forward slash
'D:/x88_2.csv'

Categories