Open XanaDublaKublaConch opened 4 years ago
I just arrived at that SO answer and this issue, and can confirm the problem. Tried both Python 3.8.8 (64-bit) and Python 3.8.7 (32-bit), on Windows 10 with PyWin32 2.2.8.
Test codes:
>>> from win32com.client import Dispatch, gencache
>>> onenote = Dispatch("OneNote.Application.15") # The same problem with "OneNote.Application"
>>> onenote.GetHierarchy("", 4)
Traceback (most recent call last):
File "C:\Users\...\Local\Temp/ipykernel_16612/1769498471.py", line 1, in <module>
onenote.GetHierarchy("", 4)
File "C:\Users\...\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: OneNote.Application.15.GetHierarchy
>>> onenote15 = gencache.EnsureModule('{0EA692EE-BB50-4E3C-AEF0-356D91732725}', 0, 1, 1)
>>> onenote = onenote15.Application()
>>> onenote.GetHierarchy("", 4)
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Temp/ipykernel_16612/1769498471.py", line 1, in <module>
onenote.GetHierarchy("", 4)
File "C:\Users\...\AppData\Local\Temp\gen_py\3.8\0EA692EE-BB50-4E3C-AEF0-356D91732725x0x1x1.py", line 181, in GetHierarchy
return self._ApplyTypes_(1610743808, 1, (24, 0), ((8, 1), (3, 1), (16392, 2), (3, 49)), 'GetHierarchy', None,bstrStartNodeID
File "C:\Users\...\Anaconda3\lib\site-packages\win32com\client\__init__.py", line 467, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
com_error: (-2147319779, 'Biblioteca não registrada.', None, None)
"Biblioteca não registrada" means "Library not registered".
>>> onenote = gencache.EnsureDispatch('OneNote.Application.15')
Traceback (most recent call last):
File "C:\Users\...\Anaconda3\lib\site-packages\win32com\client\gencache.py", line 530, in EnsureDispatch
ti = disp._oleobj_.GetTypeInfo()
com_error: (-2147467259, 'Erro não especificado', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Temp/ipykernel_16612/420472713.py", line 1, in <module>
onenote = gencache.EnsureDispatch('OneNote.Application.15')
File "C:\Users\...\Anaconda3\lib\site-packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process - please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run makepy manually for this object
"Erro não especificado" means "Unspecified error".
I can confirm this issue still persists in 2024.
I don't see evidence of a pywin32 bug here nor any thing we could do to work around it.
What you probably can do though is the "please run makepy manually for this object" part - from an elevated cmd-prompt, run makepy.py.
The places I was trying to use this did not give me elevated rights. I just converted my old VBScript stuff to Powershell for this one use case. Everything else is Python. As I said in my original post in 2020, VBScript and Powershell can instantiate and use the object with normal user rights, but those are both MS, so maybe they're using something undocumented?
What you probably can do though is the "please run makepy manually for this object" part - from an elevated cmd-prompt, run makepy.py.
That doesn't work for me.
Heads-up: I will probably use the wrong terms here. There appears to be an issue accessing the OneNote COM32 object because of a weird registry structure for OneNote. If you google the issue, you will see lots of references to a workaround, which is editing the registry node for HKEY_CLASSES_ROOT\TypeLib{0EA692EE-BB50-4E3C-AEF0-356D91732725} to delete a bogus 1.0 key for the automation lib: https://github.com/varunsrin/one-py (see the bottomt) https://stackoverflow.com/questions/16287432/python-pywin-onenote-com-onenote-application-15-cannot-automate-the-makepy-p
Although the workaround does "solve the problem" there are many instances where admin rights are not available and/or group policy repairs the registry regularly, so the fix is temporary.
Both powershell and Visual Basic can access the automation object with the registry as-is. As a side note, 0EA692EE-BB50-4E3C-AEF0-356D91732725x0x1x1.py does actually get created.
Expected behavior: dispatch a OneNote.Application.15 object.
Actual behavior: TypeError: This COM object can not automate the makepy process - please run makepy manually for this object
Steps to reproduce the problem: Brand new installation of Office with the desktop OneNote 2016 application. import win32com.client onObj = win32com.client.gencache.EnsureDispatch("OneNote.Application.15")
Version of Python and pywin32: Python: v3.8.1:1b293b6 (version doesn't matter) PyWin32: 2.2.7