sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
373 stars 150 forks source link

Com Error Type Mismatch #458

Closed solidubash closed 2 years ago

solidubash commented 2 years ago

Hi,

I am receiving an error when trying to use the COM method to connect to a local windows 11 SAS server in a jupyter notebook. I would prefer not to install Java unless absolutely necessary.

Thank you for any help you may provide.

code: import saspy sas = saspy.SASsession() sas cars = sas.sasdata('cars', 'sashelp') cars.head()

output:

Using SAS Config named: iomcom

com_error Traceback (most recent call last) Input In [1], in <cell line: 2>() 1 import saspy ----> 2 sas = saspy.SASsession() 3 sas 4 cars = sas.sasdata('cars', 'sashelp')

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\saspy\sasbase.py:551, in SASsession.init(self, kwargs) 549 self._io = SASsessionIOM(sascfgname=self.sascfg.name, sb=self, kwargs) 550 elif self.sascfg.mode == 'COM': --> 551 self._io = SASSessionCOM(sascfgname=self.sascfg.name, sb=self, kwargs) 552 elif self.sascfg.mode == 'HTTP': 553 self._io = SASsessionHTTP(sascfgname=self.sascfg.name, sb=self, kwargs)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\saspy\sasiocom.py:204, in SASSessionCOM.init(self, kwargs) 201 self.sascfg = SASConfigCOM(kwargs) 202 self._sb = kwargs.get('sb') --> 204 self.pid = self._startsas()

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\saspy\sasiocom.py:239, in SASSessionCOM._startsas(self) 233 else: 234 # Create a remote connection. The following are required: 235 # 1. host 236 # 2. port 237 # 3. class_id 238 server.MachineDNSName = self.sascfg.host --> 239 server.Port = self.sascfg.port 240 server.Protocol = self.PROTOCOL_IOM 241 server.ClassIdentifier = self.sascfg.class_id

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\win32com\client\dynamic.py:686, in CDispatch.setattr(self, attr, value) 682 entry = self.olerepr.propMapPut[attr] 683 invoke_type = _GetDescInvokeType( 684 entry, pythoncom.INVOKE_PROPERTYPUT 685 ) --> 686 self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value) 687 return 688 try:

com_error: (-2147352571, 'Type mismatch.', None, 1)

Desktop (please complete the following information):

tomweber-sas commented 2 years ago

Hey, I can try to help you with this. Can I see your configuration, for starters? It looks like you were trying to provide a host and port, which would be for a remote connection? But you said you're trying to connect locally? FWIW, you should really use the IOM access method, it's fully supported and performs much better. Since you have SAS on your machine, you already have Java in that install. You can just point to java in your SAS deployment and be up and running.

solidubash commented 2 years ago

Hi Tom,

Thanks for the quick response.

When I try running the IOM with Java access, I receive the following:

Using SAS Config named: winlocal The OS Error was: The system cannot find the file specified

my sascfg_personal.py is as follows:

winlocal = {'java' : 'C:\Program Files\SASHome\SASPrivateJavaRuntimeEnvironment\9.4\jre\bin\java.exe', 'encoding' : 'windows-1252', }

Any suggestions for where to point it for the Java in my SAS deployment?

Thanks!

tomweber-sas commented 2 years ago

Hey, that looks like the right location. So I'm guessing it's the same old windows problem with paths. Windows python thinks string with '\''s in them are escape sequences. You have to either use double backslashes or add the r'blabla' (raw designation for a string), to get he path to be correct. Code either of these and try it:

'java' : 'C:\\Program Files\\SASHome\\SASPrivateJavaRuntimeEnvironment\\9.4\\jre\\bin\\java.exe',
'java' : r'C:\Program Files\SASHome\SASPrivateJavaRuntimeEnvironment\9.4\jre\bin\java.exe',
solidubash commented 2 years ago

Solved! Thanks for your help. Closing this issue.

tomweber-sas commented 2 years ago

Sweet!

solidubash commented 2 years ago

Well, it turns out it's only half solved. The python kernel will run SAS, but the SAS kernel throws an error "Failed to Start. Unhandled error" Traceback (most recent call last): File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\web.py", line 1704, in _execute result = await result File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 304, in wakeup future.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\gen.py", line 769, in run yielded = self.gen.throw(exc_info) # type: ignore File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\notebook\services\sessions\handlers.py", line 74, in post model = yield maybe_future( File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\gen.py", line 762, in run value = future.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\gen.py", line 769, in run yielded = self.gen.throw(exc_info) # type: ignore File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 98, in create_session kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\gen.py", line 762, in run value = future.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\gen.py", line 769, in run yielded = self.gen.throw(*exc_info) # type: ignore File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 110, in start_kernel_for_session kernel_id = yield maybe_future( File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\gen.py", line 762, in run value = future.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\futures.py", line 201, in result raise self._exception File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 232, in __step result = coro.send(None) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 176, in start_kernel kernel_id = await maybe_future(self.pinned_superclass.start_kernel(self, **kwargs)) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\utils.py", line 30, in wrapped raise e File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\utils.py", line 27, in wrapped return loop.run_until_complete(future) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\nest_asyncio.py", line 89, in run_until_complete return f.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\futures.py", line 201, in result raise self._exception File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 232, in step result = coro.send(None) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\multikernelmanager.py", line 212, in _async_start_kernel starter = ensure_async(km.start_kernel(*kwargs)) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\utils.py", line 30, in wrapped raise e File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\utils.py", line 27, in wrapped return loop.run_until_complete(future) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\nest_asyncio.py", line 89, in run_until_complete return f.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\futures.py", line 201, in result raise self._exception File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 232, in __step result = coro.send(None) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\manager.py", line 83, in wrapper raise e File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\manager.py", line 75, in wrapper out = await method(self, args, kwargs) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\manager.py", line 387, in _async_start_kernel await ensure_async(self._launch_kernel(kernel_cmd, kw)) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\utils.py", line 30, in wrapped raise e File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\utils.py", line 27, in wrapped return loop.run_until_complete(future) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\nest_asyncio.py", line 89, in run_until_complete return f.result() File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\futures.py", line 201, in result raise self._exception File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 232, in step result = coro.send(None) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\manager.py", line 307, in _async_launch_kernel connection_info = await self.provisioner.launch_kernel(kernel_cmd, kw) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\provisioning\local_provisioner.py", line 204, in launch_kernel self.process = launch_kernel(cmd, scrubbed_kwargs) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\launcher.py", line 170, in launch_kernel raise ex File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_client\launcher.py", line 158, in launch_kernel proc = Popen(cmd, **kwargs) File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\$username\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified

Any suggestions? Username changed to $username for privacy

tomweber-sas commented 2 years ago

Well, try restarting the kernel. That SAS_Kernel, just uses saspy under the covers. it's the same error about file not found, so like anything on windows, try restarting it and see if it works :)

tomweber-sas commented 2 years ago

Course, the traceback isn't from saspy at all, it almost seems like it's trying to start a subprocess for the SAS_kernel, and it's not found or something. The traceback never got to anything having to do with saspy. But, restarting it can't hurt.

solidubash commented 2 years ago

That was my first thought too. Tried a full restart of the workstation, first. Any other suggestions? Thanks!

tomweber-sas commented 2 years ago

Well, have you used the SAS_kernel before? Are you sure it's installed correctly? I don't see anything from that traceback to give a clue about what file it doesn't think is found. That's not the saspy one about java.

tomweber-sas commented 2 years ago

Do you have multiple environments (python)? That gets folks into trouble a lot; having something installed in one, but running in the other, ... Anything like that maybe?

solidubash commented 2 years ago

Turns out the kernel.json file for jupyter was pointing to the wrong environment. Thanks again!