Reputation: 11
I am writing a Python program to print out a document. However, If I try to print something out a second time, I get an error stating 'RPC Server Unavailable"
Here is my code, using win32com and docxtpl
def printWordDocument(filename):
word.Documents.Open(filename)
word.ActiveDocument.PrintOut()
time.sleep(2)
word.ActiveDocument.Close()
def createDocument(n, a, z, c, nu):
name = n
addr = a
csz = z
court = c
num = nu
nup = n.upper()
context = {'name': n, 'addr': a, 'csz': z, 'court': court, 'name_up': nup,
'num': nu}
doc.render(context)
doc.save("C:\\Users\\mark\\Automations\\pt_generated.docx")
printWordDocument("C:\\Users\\mark\\Automations\\pt_generated.docx")
def submitFunction():
name = name_entry.get()
addr = addr_entry.get()
csz = csz_entry.get()
court = csz_entry.get()
num = num_entry.get()
createDocument(name, addr, csz, court, num)
word.Quit()
os.remove("C:\\Users\\mark\\Automations\\pt_generated.docx")
clearAddr()
The submitFunction() gets called first.
And this is the error I get when I try to print out something more than once:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\mark\Automations\pt.py", line 98, in submitFunction
word.Quit()
File "<COMObject Word.Application>", line 2, in Quit
pywintypes.com_error: (-2147023174, 'The RPC server is unavailable.', None, None)
From the research I've done, it seems that this error is the result of a COM object not being properly released. However, I am calling word.Quit(), which should be releasing the document, so I am not sure what I am doing wrong.
Solution: Turns out that the line word.Quit()
was causing this. Once i removed it it worked.
Upvotes: 0
Views: 479