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

Can't connect to sas server from jupyter server with stdio #343

Closed mdpetrov closed 3 years ago

mdpetrov commented 3 years ago

I have SAS server (UNIX) and jupyter client working on the same server. SAS directory is /opt/sas/sas9.4_m/SASFoundation/9.4/sas. Jupyter directory is /home/sai/anaconda3/. So, all I need is local connection from python to SAS. I edited sascfg.py and wrote down the following:

default  = {'saspath'  : '/opt/sas/sas9.4_m/SASFoundation/9.4/sas',
            'options'   : ['-autoexec /opt/sas/sas_data_config/slicelibs.sas']
}

autoexec option is needed because of specificity of current SAS server.

Then I tried to establish a new connection using jupyter notebook:

import pandas as pd
import numpy as np
import saspy
import sys
sas = saspy.SASsession(cfgname='default', cfgfile='/data2/Jupyter/pmd/sascfg.py')

where /data2/Jupyter/pmd/sascfg.py is a path to my edited sascfg.py.

But I get the following error:

SAS Connection failed. No connection established. Double check your settings in sascfg_personal.py file.

Attempted to run program /opt/sas/sas9.4_m/SASFoundation/9.4/sas with the following parameters:['/opt/sas/sas9.4_m/SASFoundation/9.4/sas', '-autoexec /opt/sas/sas_data_config/slicelibs.sas', '-fullstimer', '-nodms', '-stdio', '-terminal', '-nosyntaxcheck', '-pagesize', 'MAX', '']

Try running the following command (where saspy is running) manually to see if you can get more information on what went wrong:
/opt/sas/sas9.4_m/SASFoundation/9.4/sas -autoexec /opt/sas/sas_data_config/slicelibs.sas -nodms -stdio -terminal -nosyntaxcheck -pagesize MAX  

No SAS process attached. SAS process has terminated unexpectedly.
Invalid response from SAS on inital submission. printing the SASLOG as diagnostic

Then I tried to establish SAS connection with UNIX command line (using the putty): image

And what I got is nothing. When I'm trying to send any command futher it gives me nothing in the output. I pressed Ctrl+C and terminate session: image

Then I tried to run SAS session with putty without -stdio argument. And I realised that I established a working SAS connection. Here is part of the output: image

It's working and I can send any command to SAS server and get reliable output.

So the question is: can I run connection from the jupyter without stdio argument? Or what can I do in order to establish connection from jupyter in this situation?

tomweber-sas commented 3 years ago

Hey, I think the issue is just that you should use the SAS startup script, instead of the SAS command itself. You should have the following scripts (at least), in /opt/sas/sas9.4_m/SASFoundation/9.4/bin : sas_en, sas_u8, ... So if you change your path to whichever script (language based), this should work. The scripts include the appropriate sasv9.cfg file from your install, and start up SAS so this all works like it should. So, path='/opt/sas/sas9.4_m/SASFoundation/9.4/bin/sas_xx' (sas_en, sas_u8 ...) Can you give that a try? Thanks, Tom

mdpetrov commented 3 years ago

Thank you for your answer! Unfortunally, the problem is the same :( I tried in python and also command line with sas_u8, sas_ru, sas_en.

tomweber-sas commented 3 years ago

The original error has this in it, did it print out anything for the log?

No SAS process attached. SAS process has terminated unexpectedly.
Invalid response from SAS on inital submission. printing the SASLOG as diagnostic
tomweber-sas commented 3 years ago

There are two other things, we can do to help diagnose this. Not knowing what's in that autoexec, can you try without that, just to eliminate anything it maybe doing? Can you show me what's in there? You can always email me anything you don't want to post here. The other is to run the following in your interactive session (with the autoexec, so it's the same), and show me the output:

 data _null_; length x $ 4096; 
7                   x = resolve('%sysfunc(pathname(work))');  put 'WORKPATH=' x 'WORKPATHEND=';
8                   x = resolve('&SYSENCODING');              put 'ENCODING=' x 'ENCODINGEND=';
9                   x = resolve('&SYSVLONG4');                put 'SYSVLONG=' x 'SYSVLONGEND=';
10                  x = resolve('&SYSJOBID');                 put 'SYSJOBID=' x 'SYSJOBIDEND=';
11                  x = resolve('&SYSSCP');                     put 'SYSSCP=' x 'SYSSCPEND=';
12               run;

Thanks, Tom

tomweber-sas commented 3 years ago

Ah, and I think I may have overlooked the problem first! I think it's a problem with your options statement:

'options'   : ['-autoexec /opt/sas/sas_data_config/slicelibs.sas']

should be coded ass follows. Can you fix that and try (still with the scripts instead of the command)

'options'   : ['-autoexec', '/opt/sas/sas_data_config/slicelibs.sas']

I think it's just SAS failing with the error on startup since the syntax for the options is incorrect. Tom

mdpetrov commented 3 years ago

Sorry for a long answer, I had couple day-offs from work out of town :)

  1. The original error has this in it, did it print out anything for the log?

    No SAS process attached. SAS process has terminated unexpectedly.
    Invalid response from SAS on inital submission. printing the SASLOG as diagnostic

Yes, the error was the same as when I executed original SAS file. The same result is when running without autoexec option and running with -noautoexec option. What is more sometimes it outputs error but sometimes it just "freezes" untill I interrupt kernel.

2.

Not knowing what's in that autoexec, can you try without that, just to eliminate anything it maybe doing?

It just assigns some system libs, including spde libs and creates some macroses that are also nedeed during the work. I don't think I can share it because of NDA, but I'm sure there is nothing dangerous in it.

3.

The other is to run the following in your interactive session (with the autoexec, so it's the same), and show me the output:

I ran your script in another SAS session (started it directly from EG with autoexec), results are below:

WORKPATH=/data2/sas_user_tmp/pmd/SAS_work6E65000F054D_plc8-sas-01.equifax.local WORKPATHEND=
ENCODING=wcyrillic ENCODINGEND=
SYSVLONG=9.04.01M4P11092016 SYSVLONGEND=
SYSJOBID=984397 SYSJOBIDEND=
SYSSCP=LIN X64 SYSSCPEND=

4.

'options' : ['-autoexec /opt/sas/sas_data_config/slicelibs.sas']

Also fixed that, but nothing changed :(

BTW, don't u know, can I start SAS session in python directly by direct opening SAS file (sas_eng) with parameters without using SASPY?

tomweber-sas commented 3 years ago

The way the options list was coded will cause SAS to fail, and you may or may not get a log; depends on timing since it's a start up failure. Can I see the error from trying with the correct options parameter? As for just running a SAS program from python, sure, python lets you execute a program os.exec() I think; have to look it up. But that's just like the X command in SAS; you're just executing a command or batch job via that; not having an interactive session.

mdpetrov commented 3 years ago

Do you mean this?

SAS Connection failed. No connection established. Double check your settings in sascfg_personal.py file.

Attempted to run program /opt/sas/sas9.4_m/SASFoundation/9.4/bin/sas_en with the following parameters:['/opt/sas/sas9.4_m/SASFoundation/9.4/bin/sas_en', '-autoexec', '/opt/sas/sas_data_config/slicelibs.sas', '-nodms', '-stdio', '-terminal', '-nosyntaxcheck', '-pagesize', 'MAX', '']

Try running the following command (where saspy is running) manually to see if you can get more information on what went wrong:
/opt/sas/sas9.4_m/SASFoundation/9.4/bin/sas_en -autoexec /opt/sas/sas_data_config/slicelibs.sas -nodms -stdio -terminal -nosyntaxcheck -pagesize MAX  

No SAS process attached. SAS process has terminated unexpectedly.
Invalid response from SAS on inital submission. printing the SASLOG as diagnostic
mdpetrov commented 3 years ago

Tom, I also tried to connect using Java, but again I got error. I dont't know what method of connection is easier to repair (STDIO or JAVA), but just in case I copy-paste an error from JAVA connection. I saw your solution for Windows (with -config option) but it seems not working for me (because I have UNIX server).

What do you think about that?

Java Error:
log4j:WARN No appenders could be found for logger (com.sas.services.connection).
log4j:WARN Please initialize the log4j system properly.
com.sas.services.connection.FatalConnectionFactoryException: The application could not log on to the server. The server process terminated unexpectedly with exit value 116.
    at com.sas.services.connection.ClusterEnvelope.getConnection(ClusterEnvelope.java:248)
    at com.sas.services.connection.AggregationKernel.doGetConnection(AggregationKernel.java:242)
    at com.sas.services.connection.ConnectionFactoryKernel.getConnection(ConnectionFactoryKernel.java:325)
    at com.sas.services.connection.ConnectionFactoryShell.getConnection(ConnectionFactoryShell.java:69)
    at com.sas.services.connection.ConnectionFactoryShell.getConnection(ConnectionFactoryShell.java:51)
    at pyiom.saspy2j.main(saspy2j.java:198)
Caused by: org.omg.CORBA.BAD_PARAM: The application could not log on to the server. The server process terminated unexpectedly with exit value 116.  vmcid: 0x0  minor code: 0  completed: No
    at com.sas.iom.orb.brg.Engine$4.run(Engine.java:3477)
    at java.lang.Thread.run(Thread.java:745)

We failed in getConnection
The application could not log on to the server. The server process terminated unexpectedly with exit value 116.
SAS Connection failed. No connection established. Staus=(286250, 64000)  Double check your settings in sascfg_personal.py file.

Attempted to run program /opt/sas/sas9.4_m/SASPrivateJavaRuntimeEnvironment/9.4/jre/bin/java with the following parameters:['/opt/sas/sas9.4_m/SASPrivateJavaRuntimeEnvironment/9.4/jre/bin/java', '-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd="/opt/sas/sas9.4_m/SASFoundation/9.4/sas"', '-classpath', '/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/saspyiom.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/log4j.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.security.sspi.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.core.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.svc.connection.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.rutil.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.rutil.nls.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sastpj.rutil.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/glassfish-corba-internal-api.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/glassfish-corba-omgapi.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/glassfish-corba-orb.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/pfl-basic.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/pfl-tf.jar', 'pyiom.saspy2j', '-host', 'localhost', '-stdinport', '46533', '-stdoutport', '33996', '-stderrport', '45759', '-zero', '-lrecl', '1048576', '']

If no Java Error above, try running the following command (where saspy is running) manually to see if it's a problem starting Java:
/opt/sas/sas9.4_m/SASPrivateJavaRuntimeEnvironment/9.4/jre/bin/java -Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd="/opt/sas/sas9.4_m/SASFoundation/9.4/sas" -classpath /home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/saspyiom.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/log4j.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.security.sspi.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.core.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.svc.connection.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.rutil.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sas.rutil.nls.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/iomclient/sastpj.rutil.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/glassfish-corba-internal-api.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/glassfish-corba-omgapi.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/glassfish-corba-orb.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/pfl-basic.jar:/home/sai/anaconda3/lib/python3.6/site-packages/saspy/java/thirdparty/pfl-tf.jar pyiom.saspy2j -host localhost -stdinport 46533 -stdoutport 33996 -stderrport 45759 -zero -lrecl 1048576  

No SAS process attached. SAS process has terminated unexpectedly.
Invalid response from SAS on inital submission. printing the SASLOG as diagnostic
tomweber-sas commented 3 years ago

Yes, thanks. I wanted to actually see the error with the code you ran, with the proper syntax. That looks right. So, SAS is still failing to start, but I don't see anything showing why that would be, or what the error is.

As for using the IOM access method, that's for connecting to a Workspace server. If this is just a stand alone install, it won't connect to that. For a Windows SAS, stand alone, install, IOM is the only way to connect to it, as SAS on windows doesn't support STDIO and IOM has a special case for connecting to this even though it's not an actual workspace server. So if your Linux SAS is just stand alone, then STDIO is the only way.

And, you are really on the same machine; python is running on the machine that the SAS install is on? You mentioned using putty above, and I don't know if that means you're using putty to remotely connect to the machine SAS is on and trying to run SAS? Do you use putty to connect to that machine and run python from there? Can you confirm that the python your running saspy in is actually on the machine SAS is on?

If you have time to do a web-ex or teams meeting, I may be able to see what's happening if I can see what's going on and try out some things. Is that an option?

Thanks, Tom

tomweber-sas commented 3 years ago

Have you found out anything more on this? If python and SAS aren't on the same linux machine, you can use STDIO over SSH to access the remote SAS. I'm still thinking this may be the case. If the path= you specify isn't valid (is on a different machine, or just isn't correct), that would be a reason for SAS to not start up and could cause this error, with no log or other info. Is there anything else I can do to help you with this? Thanks, Tom

tomweber-sas commented 3 years ago

Hey, I' gonna close this due to inactivity. Hopefully you figured out what was wrong and got it working. If you need more help, feel free to reopen this or create a new one. Thanks, Tom