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
366 stars 149 forks source link

No server is available at that port on that machine #583

Closed jdsmith65 closed 5 months ago

jdsmith65 commented 5 months ago

Hi, there,

I am trying to use SASpy, but am getting a connection error.

The setup

Here is my code that installs the package and sets it up: import os import subprocess

def install_saspy(env_name):

Install saspy in the specified environment

subprocess.run(["conda", "install", "-n", env_name, "saspy"], check=True)

def create_sascfg_personal():

Define the directory to the sascfg_personal.py in the user's home directory within .config/saspy/

sascfg_directory = os.path.expanduser("~/.config/saspy/")
path_to_sascfg = os.path.join(sascfg_directory, 'sascfg_personal.py')

# Make sure the directory exists
os.makedirs(sascfg_directory, exist_ok=True)

sascfg_content = """

SAS_config_names=['oda'] oda = {'java' : '/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home/bin/java', 'iomhost' : ['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com'], 'iomport' : 8591, 'authkey' : 'oda', 'encoding' : 'utf-8' } """

with open(path_to_sascfg, "w") as f:
    f.write(sascfg_content)

def create_authinfo(): authinfo_content = "oda user RealUserName password MyRealPassword"

Set path directly under the user's home directory.

path_to_authinfo = os.path.expanduser("~/.authinfo")
with open(path_to_authinfo, "w") as f:
    f.write(authinfo_content)

def setup_saspy(env_name): install_saspy(env_name) create_sascfg_personal() create_authinfo()

I can successfully use setup_saspy and then import saspy. I saw in another closed issue that there are SAS jar files to be used, so I've pasted them into (what I think is) the correct folder: "/Users/jaredsmith/anaconda3/envs/foodfinance/lib/python3.11/site-packages/saspy/java/iomclient"

The Error

However, when I attempt to connect I get this error: sas_session = saspy.SASsession() Using SAS Config named: oda We failed in getConnection The application could not log on to the server "odaws04-usw2.oda.sas.com:8591". No server is available at that port on that machine.

SAS process has terminated unexpectedly. Pid State= (72687, 64000) Traceback (most recent call last):

Cell In[2], line 1 sas_session = saspy.SASsession()

File ~/anaconda3/envs/foodfinance/lib/python3.11/site-packages/saspy/sasbase.py:562 in init self._io = SASsessionIOM(sascfgname=self.sascfg.name, sb=self, **kwargs)

File ~/anaconda3/envs/foodfinance/lib/python3.11/site-packages/saspy/sasioiom.py:300 in init self._startsas()

File ~/anaconda3/envs/foodfinance/lib/python3.11/site-packages/saspy/sasioiom.py:556 in _startsas ll = self.submit("options svgtitle='svgtitle'; options validvarname=any validmemname=extend pagesize=max nosyntaxcheck; ods graphics on;", "text")

File ~/anaconda3/envs/foodfinance/lib/python3.11/site-packages/saspy/sasioiom.py:963 in submit raise SASIOConnectionTerminated(Exception)

SASIOConnectionTerminated: <class 'Exception'>

Additional Details

I am using Python 3.11.6 inside a Conda environment and saspy version 5.5.0. I work for a university and have tried to connect at home with and without a VPN and while on campus.

Please let me know what I am doing wrong.

Thanks!

github-actions[bot] commented 5 months ago

Hey, I'm OOO till Jan 29th. I will reply to this then! Sorry for the delay. Thanks, Tom

tomweber-sas commented 5 months ago

Hey @jdsmith65, sorry for the OOO reply, I was trying to get that set up yester as I will be out after today. Looking at the error, it's likely to simply be that you're using the wrong set of servers for your account/region. Somewhat recently, ODA added a second set of server in the US region. The first thing to try would be to add those to your iomhost list, or replace it with those, as there's no point trying 4 servers that we know aren't right, if the others turn out to be the right ones. Here's the doc: https://support.sas.com/ondemand/saspy.html And here's the relevant couple lines:

US Home Region 1

'iomhost' : ['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com'],

US Home Region 2

'iomhost' : ['odaws01-usw2-2.oda.sas.com','odaws02-usw2-2.oda.sas.com'],

Can you swap out your iomhost list with ['odaws01-usw2-2.oda.sas.com','odaws02-usw2-2.oda.sas.com'], and see if you can connect?

Thanks, Tom

jdsmith65 commented 5 months ago

Connection established!

Thanks for your help. Easy fix.

Best, Jared

tomweber-sas commented 5 months ago

Sweet!, That's how I like 'em, lol :) Glad that was all it was.