BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Santt0sh
Lapis Lazuli | Level 10
Hi All,
 
I am learning to use Python/Jupyter Notebook, I have followed all steps provided in the support doc but i'm still unable to start a SASsession.
Can any of the SAS experts help fix this Syntax error(SyntaxError: invalid syntax)? 
 
import saspy
sas_session = saspy.SASsession()
sas_session
 
 
Please find the error below after i import the saspy and start a SASsession.
Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-20-0483c802e9d9>", line 2, in <module>
    sas_session = saspy.SASsession()

  File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 465, in __init__
    self.sascfg            = SASconfig(**kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 129, in __init__
    SAScfg = self._find_config(cfg_override=kwargs.get('cfgfile'))

  File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 332, in _find_config
    import sascfg_personal as SAScfg

  File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sascfg_personal.py", line 6
    'iomhost' :['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com']
    ^
SyntaxError: invalid syntax
1 ACCEPTED SOLUTION

Accepted Solutions
gwootton
SAS Super FREQ
You may want to try removing the authkey option from your sascfg_personal.py.

That message seems to indicate you do not have the necessary permissions to read that file.
Does the file exist and have permissions set as outlined in https://go.documentation.sas.com/api/docsets/authinfo/9.4/content/authinfo.pdf
For the server name, have you specified the value in your authkey option?
--
Greg Wootton | Principal Systems Technical Support Engineer

View solution in original post

18 REPLIES 18
Sajid01
Meteorite | Level 14

Can we have the output of the following.

import saspy
sas_session = saspy.SASsession()
I hope you are using SAS studio.
If not what is your setup / environment.

Santt0sh
Lapis Lazuli | Level 10
Thanks for your quick response, yes i am using SAS Studio.
import saspy
sas_session = saspy.SASsession()
Please find the output below.
==========================================
Traceback (most recent call last):

File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File "<ipython-input-2-6370c5ed4af2>", line 2, in <module>
sas_session = saspy.SASsession()

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 465, in __init__
self.sascfg = SASconfig(**kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 129, in __init__
SAScfg = self._find_config(cfg_override=kwargs.get('cfgfile'))

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 332, in _find_config
import sascfg_personal as SAScfg

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sascfg_personal.py", line 6
'iomhost' :['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com']
^
SyntaxError: invalid syntax
gwootton
SAS Super FREQ

It looks like the problem is with your sascfg_personal.py file's syntax for that iomhost option. The example in the default sascfg.py is:

iomlinux = {'java' : '/usr/bin/java',
'iomhost' : 'linux.iom.host',
'iomport' : 8591,
}
--
Greg Wootton | Principal Systems Technical Support Engineer
Santt0sh
Lapis Lazuli | Level 10
Hi Greg,

Thanks for your reply,

This is my sascfg_personal.py and the error is for a particular line.
'iomhost' :['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com']


Kindly Suggest!!
====================================================
SAS_config_names=['oda']
oda = {'java' : 'C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath\\java.exe',
#US Home Region
US
#'iomhost' : ['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com'],
'iomhost' :['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com']
#European Home Region
#'iomhost' : ['odaws01-euw1.oda.sas.com','odaws02-euw1.oda.sas.com'],
#Asia Pacific Home Region
#'iomhost' : ['odaws01-apse1.oda.sas.com','odaws02-apse1.oda.sas.com'],
'iomport' : 8591,
'authkey' : 'oda',
'encoding' : 'utf-8'
}
gwootton
SAS Super FREQ

Should "US" be commented out there?

Also, should there be a comma at the end of your uncommented iomhost line?

--
Greg Wootton | Principal Systems Technical Support Engineer
Santt0sh
Lapis Lazuli | Level 10
Hi Greg,

yes you were correct US should be Commented and after i commented i ma getting a new error. i m trying to resolve this error, Please suggest me on this .
Thanks.
=======================================
Traceback (most recent call last):

File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File "<ipython-input-3-6370c5ed4af2>", line 2, in <module>
sas_session = saspy.SASsession()

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 465, in __init__
self.sascfg = SASconfig(**kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 129, in __init__
SAScfg = self._find_config(cfg_override=kwargs.get('cfgfile'))

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py", line 332, in _find_config
import sascfg_personal as SAScfg

File "C:\ProgramData\Anaconda3\lib\site-packages\saspy\sascfg_personal.py", line 10
'iomport' : 8591,
^
SyntaxError: invalid syntax
gwootton
SAS Super FREQ
Did you also add the comma to the end of the iomhost line?
--
Greg Wootton | Principal Systems Technical Support Engineer
gwootton
SAS Super FREQ

Another thought would be separating your different hosts into different configs:

 

SAS_config_names=['oda','usr','eur','apr']
oda = {'java' : 'C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath\\java.exe',
#US Home Region
'iomhost' :['odaws01-usw2.oda.sas.com','odaws02-usw2.oda.sas.com','odaws03-usw2.oda.sas.com','odaws04-usw2.oda.sas.com'],
#European Home Region
#'iomhost' : ['odaws01-euw1.oda.sas.com','odaws02-euw1.oda.sas.com'],
#Asia Pacific Home Region
#'iomhost' : ['odaws01-apse1.oda.sas.com','odaws02-apse1.oda.sas.com'],
'iomport' : 8591,
'authkey' : 'oda',
'encoding' : 'utf-8'
}
usr = {'java' : 'C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath\\java.exe',
'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'
}
eur = {'java' : 'C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath\\java.exe',
'iomhost' : ['odaws01-euw1.oda.sas.com','odaws02-euw1.oda.sas.com'],
'iomport' : 8591,
'authkey' : 'oda',
'encoding' : 'utf-8'
}
apr = {'java' : 'C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath\\java.exe',
'iomhost' : ['odaws01-apse1.oda.sas.com','odaws02-apse1.oda.sas.com'],
'iomport' : 8591,
'authkey' : 'oda',
'encoding' : 'utf-8'
}
--
Greg Wootton | Principal Systems Technical Support Engineer
Santt0sh
Lapis Lazuli | Level 10
Hi George,

No, I haven't added the comma at the end of the IOM line.
gwootton
SAS Super FREQ
Let us know if doing so resolves the new error.
--
Greg Wootton | Principal Systems Technical Support Engineer
Santt0sh
Lapis Lazuli | Level 10
Hi Greg,
Nothing has changed even after add or removing the comma.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-4-99201ba30faf> in <module>
1 import saspy
----> 2 sas_session = saspy.SASsession()
3 cars=sas.sasdata('cars', 'sashelp')
4 cars.head()

C:\ProgramData\Anaconda3\lib\site-packages\saspy\sasbase.py in __init__(self, **kwargs)
535 if self.sascfg.mode != 'HTTP':
536 try:
--> 537 self.pyenc = sas_encoding_mapping[self.sascei]
538 except KeyError:
539 print("Invalid response from SAS on inital submission. printing the SASLOG as diagnostic")

KeyError: 'No SAS process attached. SAS process has terminated unexpectedly.'
gwootton
SAS Super FREQ

It looks like you are no longer encountering the syntax error...
Try this:

import saspy
from IPython.display import HTML
sas = saspy.SASsession(cfgname="oda")
c = sas.submit("""
proc setinit; run;
""")
c = sas.submit("""
proc setinit;
run;
""")
HTML(c['LOG'])
--
Greg Wootton | Principal Systems Technical Support Engineer
Santt0sh
Lapis Lazuli | Level 10
Hi Greg,
Yes now i am not getting Syntax error,
after i tried running the code.

Error trying to read authinfo file:C:\Users\santo\_authinfo
[Errno 13] Permission denied: 'C:\\Users\\santo\\_authinfo'
Did not find key oda in authinfo file:C:\Users\santo\_authinfo

Please enter the IOM user id: psantosh0
The OS Error was:
The system cannot find the file specified
==============================================================
Error trying to read authinfo file:C:\Users\santo\_authinfo
[Errno 13] Permission denied: 'C:\\Users\\santo\\_authinfo'
Did not find key oda in authinfo file:C:\Users\santo\_authinfo

Please enter the IOM user id: psantosh0
The OS Error was:
The system cannot find the file specified

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


Santt0sh
Lapis Lazuli | Level 10
Hi Greg,
Error trying to read authinfo file:C:\Users\santo\_authinfo
[Errno 13] Permission denied: 'C:\\Users\\santo\\_authinfo'
Did not find key oda in authinfo file:C:\Users\santo\_authinfo

Permissions for all the users on this folder are granted.

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 3113 views
  • 2 likes
  • 3 in conversation