I'm running pywin32 for python 2.5.
I'm following the instructions for python ADO given at http://www.ecp.cc/pyado.html.
Creating an ADODB.Recordset object works fine. But when I try to create an ADOX.Catalog object I get an error:
>>> cat=win32com.client.Dispatch(r'ADOX.Catalog')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147024770, 'The specified module could not be found.', None, None)
Any ideas what I might be missing?
Solution: even though ADOX was showing up in the COM browser as an available library, it wasn't "registered" properly. Following the instructions here, I executed the following at the Start->Run prompt:
regsvr32 "C:\Program Files\Common Files\System\ado\msadox.dll"
Note that this is on a WinXP SP2 machine. I guess the registry had become corrupt somehow? In any case, I'm new to Windows programming so my explanation may be off, but maybe the fix will help someone.
Related
I am trying to open and run a multisim simulation from python using the multisim COM interface.
from research I understand multisim has a COM interface that can be accessed from any other program using any language.
here's an example of it working (partially) with MATLAB
however, I cannot get it to work with python. when I try to open the API I get an error.
here's the Python code, I am using the win32com module:
import win32com.client as win
win.Dispatch("MultisimInterface.MultisimApp")
however, I get a "class not registered" error. the full message is:
Traceback (most recent call last):
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
win.Dispatch("MultisimInterface.MultisimApp")
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\__init__.py", line 117, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 88, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
It appears for some reason multisim is not opening its API. I have tested the code and tried to open LABVIEW and Excel using the same code and it worked, so I don't know why it doesn't work with multisim.
is there a way to see which interfaces are registered and can be accessed on a given time? will it work better using another language? am I missing something on a much more basic level?
I would appreciate any help. thanks in advance
When I try to run a script that opens up Adobe Photoshop 2022, I'm met with following errors:
Traceback (most recent call last):
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\XXXXX\XXXXX\XXXXX\XXXXX\Python\Autophoto\Autophoto.py", line 39, in <module>
psApp = win32com.client.Dispatch("Photoshop.Application")
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\__init__.py", line 117, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch, None, clsctx, pythoncom.IID_IDispatch
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
The win32com.client.Dispatch("Photoshop.Application") call used to work when an older version of Photoshop was installed, but since I've updated it to the latest version, the code no longer seems to work.
I've tried using the win32com tool to list all COM interfaces but this program seems to crash after a few seconds every time.
Any tips?
(The code is accessible via following link: https://github.com/samualon/Autophoto)
I am trying to work with Outlook Redemption using Python. Currently I am hitting an error just trying to get things working.
import win32com.client
session = win32com.client.Dispatch("Redemption.RDOSession")
However, I am getting this error.
Traceback (most recent call last):
File "Test.py", line 3, in <module>
session = win32com.client.Dispatch("Redemption.RDOSession")
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 114, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
pywintypes.com_error: (-2147221233, 'OLE error 0x8004010f', None, None)
I am pretty sure that I have Redemption installed correctly, along with MAPI, and the win32com package for python. I've double checked all three of their installations and nothing has changed.
I currently do not have Outlook or Exchange installed on this computer. Could this be the issue?
Has anyone else hit this error before?
The error is MAPI_E_NOT_FOUND. Most likely that means the MAPI system (Outlook) is not installed, or that it is of a wrong bitness different from that of your app.
What is the bitness of your app, Windows, and Outlook? Does the follwing apply? http://www.dimastr.com/redemption/faq.htm#ErrorCreatingRedemptionObject
I am on windows 7 and I have windows live installed.
Now when I am trying to run following code
import win32com.client
win32com.client.Dispatch("Outlook.Application")
I am getting following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
I have another machine with windows xp and Outlook installed.
I ran the same code and I got the same error.
One more question.
How can I get the com of windows live on windows 7?
Any suggestions and comments will be appreciated.
This is an indication that Outlook is not installed. "windows live" or "outlook.com" would not help you.
I was having a similar error. Have you tried running makepy.py from win32com's folder to create entries for the different COMobject's you are using? Basically, win32com just treats all of applications you interact with as default COMobjects until you let it learn about the programs installed on your computer. You'll have to run makepy.py for each program you want to control with it.
After I ran it, I gained access to much more control for Outlook. It has opened other errors that I am working on correcting.
Also, if you take your comobject (comboject = win32com.client.Dispatch("Outlook.Application")) and look at comboject._prop_map_get_.keys() you'll see all the things you can use for that program.
I'm trying to load a COM object with Python. I'm using win32com.client.Dispatch("Name.Of.Object") to load it, and the COM object has been registered with regsvr32 and appears as an entry in my registry in both HKLM/CLSID and HKLM/Wow6432Node/CLSID. I can open it using VBScript just fine, but Python's win32com.client.Dispatch() gives me this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
I have read that there are issues with 32 vs 64 bit; I'm running this on a 64-bit machine using 32-bit python and 32-bit win32com. Any suggestions?
Note that this code in VBScript works fine:
Set obj = WScript.CreateObject( "Name.Of.Object" )
Thanks
Fixed this problem by installing Python 64 bit and win32com 64 bit.