BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
krmnv
Fluorite | Level 6
I have a Python algorithm using the saspy library. I want to make it automatic through Task Scheduler. To do this, I need the login and password for saspy.SASsession to be entered automatically. How can I do that? I found only authkey, but I don’t understand how to work with it.
1 ACCEPTED SOLUTION

Accepted Solutions
sastpw
SAS Employee

Hmm, I'm sorry, it sounded like you had a working configuration and just needed to have the credentials supplied automatically.

 

winiomwin = {'authkey' : 'SASPY'}

is not a valid configuration definition. The authkey is only 1 parameter which is used to find the credentials. There are none of the required parameters in that definition to be able to know how or where to connect to your SAS system. Have you looked at the documentation that explains how to configure this: https://sassoftware.github.io/saspy/install.html#configuration?

 

As for the _authinfo file, there is no file extension. So I have to imagine you created _authinfo.txt, which isn't the correct filename. The error below, [Errno 2] No such file or directory: 'C:\\Users\\akarmanov\\_authinfo', shows that the correct file isn't there, or isn't accessible by you - it's probably the filename I would guess.

 

validvarname is not a parameter on the SASsession method. 

 

Where is the SAS system you are trying to connect to? Is it a local install? Is it a workspace server somewhere? Depending upon where it is and how you need to connect to it, the configuration definition will need different parameters; that's all in the documentation, but I can help you with that if I had more information.

 

Tom

View solution in original post

7 REPLIES 7
sastpw
SAS Employee

Hey, yes, that's what authkey is for. You store your credentials in a secured file in your home directory. First, I assume you're using an IOM access method? or HTTP? The file is named _authinfo on windows and .authinfo on linux (underscore or dot).

In the file, the format for your information is:

authkey user omr_user_id password omr_user_password

 So, for instance if your id was Bob and your password was Bobspassword, then you just need to make up a name (key) to use, let's use 'Bobs_key', and you would put a line like this in that file:

Bobs_key user Bob password Bobspassword

 Then in your saspy configuration you would code the authley paramter as follows:

'authkey' : 'Bobs_key',

 

If you have different credentials for different systems you connect to (or even the same), you would create a line in that file for each set of credentials and specify a different key for each.

 

You should set the permissions on the authinfo file to read/write only, for yourself and no access for anyone else.

 

Give it a try, it's simple and you never have to enter your credentials anymore 🙂

Tom

krmnv
Fluorite | Level 6

Tom, thanks for the response. I suppose that I am doing everything as you described, but I am facing a problem. My code looks like this:

 

winiomwin = {'authkey' : 'SASPY'}

import saspy

sas = saspy.SASsession(cfgname='winiomwin', validvarname=any, authkey='SASPY')

 

Output:

 

Error trying to read authinfo file:C:\Users\akarmanov\_authinfo

 

[Errno 2] No such file or directory: 'C:\\Users\\akarmanov\\_authinfo'

 

Did not find key SASPY in authinfo file:C:\Users\akarmanov\_authinfo

 

What is the reason and how to eliminate it?
I also have a few questions. What type of file should _authinfo have? The home directory is the path specified in the output, as I understand it. Could there be problems with this if the code runs from the server?

sastpw
SAS Employee

Hmm, I'm sorry, it sounded like you had a working configuration and just needed to have the credentials supplied automatically.

 

winiomwin = {'authkey' : 'SASPY'}

is not a valid configuration definition. The authkey is only 1 parameter which is used to find the credentials. There are none of the required parameters in that definition to be able to know how or where to connect to your SAS system. Have you looked at the documentation that explains how to configure this: https://sassoftware.github.io/saspy/install.html#configuration?

 

As for the _authinfo file, there is no file extension. So I have to imagine you created _authinfo.txt, which isn't the correct filename. The error below, [Errno 2] No such file or directory: 'C:\\Users\\akarmanov\\_authinfo', shows that the correct file isn't there, or isn't accessible by you - it's probably the filename I would guess.

 

validvarname is not a parameter on the SASsession method. 

 

Where is the SAS system you are trying to connect to? Is it a local install? Is it a workspace server somewhere? Depending upon where it is and how you need to connect to it, the configuration definition will need different parameters; that's all in the documentation, but I can help you with that if I had more information.

 

Tom

krmnv
Fluorite | Level 6
Tom, thank you for the advice.

I was able to achieve what I wanted by removing the .txt extension from the _authinfo file. I also removed the validvarname parameter from SASsession, as you recommended. Very grateful to you.
sastpw
SAS Employee

Great, I'm glad that's all it was. BTW, there's another configuration definition key you can add to your configuration definition to has the validvarname option set every time you connect (if that's what you want). There's an 'autoexec':'string of SAS code;' which will be automatically executed for you when a session is established. So if you want validvarname=any every time you connect using a given configuration definition you can add

'autoexec' : 'options validvarname=any;'

and it will automatically be set for you.

 

From the doc:

autoexec -This is a string of SAS code that will be submitted upon establishing a connection. You can use this to preassign libraries you always want available, or whatever you want. Don’t confuse this with the autoexec option of SAS which specifies a sas program file to be run. That is different. This is a string of SAS code saspy will submit after the session is created, which would be after SAS already included any autoexec file if there was one.

 

Tom

jcheng311
Calcite | Level 5

Hi,

 

I have the same issue as krmnv. I already removed the extension on my _authinfo but it still gives me error: 

 

Error trying to read authinfo file:C:\Users\uxxx421\_authinfo
[Errno 2] No such file or directory: 'C:\\Users\\uxxx421\\_authinfo'
Did not find key saspykey in authinfo file:C:\Users\uxxx421\_authinfo

 

 

this is my sasfgc_personal.py - 

 

SAS_config_names=['winiomwin']

winiomwin = {'java' : 'java',
'iomhost' : 'hostname',
'iomport' : 8561,
'encoding' : 'windows-1252',
'authkey' : 'saspykey'
}

Can you help me solve this thanks!

 

 

sastpw
SAS Employee

Hey, you are getting a system error trying to open that file. It either doesn't exist or you don't have permission. That's what the error:

 

[Errno 2] No such file or directory: 'C:\\Users\\uxxx421\\_authinfo'

would be. Are you sure you have that file, named correctly, in that path?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 3231 views
  • 1 like
  • 3 in conversation