BookmarkSubscribeRSS Feed
navdeepk
Fluorite | Level 6

I am having trouble connecting sas_kernel in jupyter to SAS viya. I am currently on a free trial , I found the below spec which needs to be changed in order ti connect with SAS viya.

httpsviya = {'url' : 'https://viya.deployment.com',
'context' : 'SAS Studio compute context',
'authkey' : 'viya_user-pw',
'options' : ["fullstimer", "memsize=1G"]
}

But I am not sure on where to find and what to fill in them. Any help?

23 REPLIES 23
AhmedAl_Attar
Ammonite | Level 13

Hi @navdeepk 

Check out the SASPy configuration SASPy configuration for how to set this up

 

Hope this helps,

Ahmed

navdeepk
Fluorite | Level 6
Hi Ahmed, I did check it out as i mentioned
httpsviya = {'url' : 'https://viya.deployment.com',
'context' : 'SAS Studio compute context',
'authkey' : 'viya_user-pw',
'options' : ["fullstimer", "memsize=1G"]
}
This is what needs to be filled as per my understanding. But i am not sure on where to find for those values. Like what would the auth key be and the url be.

Ps: I am using the free trial of sas viya on web.
AhmedAl_Attar
Ammonite | Level 13

@navdeepk 

Just clarify this for me

1. When you said "Ps: I am using the free trial of sas viya on web", doesn't that imply you have a URL to access viya!?

if so, then that would be the value for the url: key

2. the SASPy configuration link I sent you, has the following

The .authinfo file (_authinfo on Windows)¶
The IOM and HTTP access methods have support for getting the required user/password 
from an authinfo file in the user’s home directory instead of prompting for it.
On linux, the file is named .authinfo and on windows, it’s _authinfo. The format of
the line in the authinfo file is as follows. The first value is the authkey value
you specify for authkey. Next is the ‘user’ key followed by the value (the user id)
and then ‘password’ key followed by its value (the user’s password).
Note that there are permission rules for this file. On linux the file must have
permissions of 600, only the user can read or write the file. On Windows, the file
should be equally locked down to where only the owner can read and write it.
Also, the encoding of this file should be UTF-8, or any encoding that has ASCII
as it’s low order 7-bits if you only use those characters in the file.
It’s read into Python as is, and thus is expected to be utf-8.

So, wherever (Windows | Linux) you are launching Jupyter from, place/create the _authinfo | .authinfo file in your home (C:\Users\<YourID> | /home/<YourID> ) directory, with the following contents 

authkey user <viya_user_id> password <viya_user_password>

Hope this helps

 

 

navdeepk
Fluorite | Level 6

I have tried it, I am getting the below error

SASHTTPauthenticateError: Failure in GET AuthToken.
Failure in GET AuthToken. Status=401
Response=b'{"error":"unauthorized","error_description":"Bad credentials"}'


Is the userId and userpassword same as the email and password I use to login to sasviya app? Or Is it something else, if yes could you tell me where to find them.

AhmedAl_Attar
Ammonite | Level 13

@navdeepk 

"Is the userId and userpassword same as the email and password I use to login to sasviya app?" 
Yes, it should be.

Please ensure the credentials (username/password) you have used in the .authinfo|_authinfo file, are correct and you can successfully login into SAS Viya when using the Viya Web Login page from your browser.

 

@sastpw  are we missing anything else here? 

   

sastpw
SAS Employee

Hey, sure I can help. First, Can you point me to where the free trial info is, so I can try it out to see; be sure I'm getting at the same thig you are. Second, Viya has more than one authentication mechanism. Are you sure it's configured to use user/pw? They've gone away from that due to 'security' and generally use the authcode mechanism in deployments these days; but I don't know how this is set up. Did you try the authcode path? In the screen shot it shows where it asks you which mechanism to use. Did you try the other? Have you successfully connected to it using any other client? Did you get instructions from the free trial saying how to connect to it (that wouldn't be for saspy, but for Studio or something)?

 

Thanks,

Tom

sastpw
SAS Employee

Ok, well, I googled viya free trial and got to it. I guess it's the same as what you're using. This is set up for authcode authentication, like I would have guessed. That requires you to go to a web page and sign in to get a one time authcode to use to sign in. Like when you log on to anything on the internet these days and they send you a one time use code you have to enter.

 

>>> sas = saspy.SASsession(url='https://azureuse011476.my-trials.sas.com')
To connect to Viya you need either an authcode or a userid/pw. Neither were provided.
Please enter which one you want to enter next. Type one of these now: [default=authcode | userid]:
The PKCE required url to authenticate with is https://azureuse011476.my-trials.sas.com/SASLogon/oauth/authorize?client_id=SASPy&response_type=code...
Please enter authcode: Q_mq25QG-GzdUPS_GzcFjhSJCWbdfhRI
Please enter the SAS Context you wish to run. Available contexts are: ['Import 9 service compute context', 'SAS Visual Forecasting compute context', 'Data Mining compute context', 'CAS Formats service compute context', 'CAS Management service compute conte
xt', 'SAS Job Execution compute context', 'SAS Studio compute context', 'Natural Language Conversations service compute context', 'SAS Model Manager compute context', 'SAS Backup job compute context'] SAS Studio compute context
SAS server started using Context SAS Studio compute context with SESSION_ID=b6181d9f-a809-41ee-9997-f136a2cf02e4-ses0000
>>> sas
Access Method = HTTP
SAS Config name = default
SAS Config file = /r/sanyo.unx.sas.com/vol/vol810/u81/sastpw/.config/saspy/sascfg_personal.py
WORK Path = /opt/sas/viya/config/var/tmp/compsrv/default/b6181d9f-a809-41ee-9997-f136a2cf02e4/SAS_work239F0000016D_sas-compute-server-035b3e9a-339d-470c-8cf2-11a28d5e0de5-4m7d5/
SAS Version = V.04.00M0P03182024
SASPy Version = 5.100.3
Teach me SAS = False
Batch = False
Results = Pandas
SAS Session Encoding = utf-8
Python Encoding value = utf_8
SAS process Pid value = 365
SASsession started = Fri Sep 13 09:27:51 2024


>>> sas.assigned_librefs()
['SASHELP', 'MAPS', 'MAPSSAS', 'MAPSGFK', 'SASUSER', 'WORK']
>>>

sastpw
SAS Employee

And, just to show you can get there from the SAS_Kernel too (which just uses SASPy under the covers). Given the following Configuration Definition in my sascfg_personal.py:

 

vft = {'url' : 'https://azureuse011476.my-trials.sas.com',
'context' : 'SAS Studio compute context',
}

 

I can connect the same (BTW, at the prompt for authcode or userid, since the default is authcode, you can just hit enter - that's why you don't see 'authcode' typed in):

sastpw_0-1726234930465.png

 

navdeepk
Fluorite | Level 6

@sastpw  Thanks for the detailed info, I am able to connect to saspy via python kernel, but through sas kernel I am directly getting unauthenticated error

[<class 'saspy.sasexceptions.SASHTTPauthenticateError'>, SASHTTPauthenticateError('Failure in GET AuthToken. Status=401\nResponse=b\'{"error":"unauthorized","error_description":"Bad credentials"}\''), <traceback object at 0x11ac1c0c0>]

It is not asking for a prompt to provide the auth key like it did in python. Is there any config step I missing here?

 

Also every time I want to use a new session should I get that auth key or is there a one time solution available?

navdeepk
Fluorite | Level 6

Its now working with sas kernel as well, after removing the .authinfo from home dir its now asking for the prompt. Can we do anything so that the prompt is not needed any more and as soon as I launch a new kernel it gets connected to sas viya?

 

 

sastpw
SAS Employee

It doesn't look like it. The way that viya system's configured, it not only requires a unique authcode every time you connect, but the url for getting the code is a different one every time also, so you're forced to have to try to connect, get the unique url and then provide the code that you get from that. This has nothing to do with saspy (though I support it as a connection mechanism), it's viya that's configured this way as the only way to connect to it.

 

Previously when they came up with this authcode scheme, the URL was fixed, so you could at least go get the code and then pass it in on the SASsession call as below. But now it uses a PKCE URL which is required and precludes being able to even know the url to get a code from because the url changes every time, just like the code. It's all in the name of security it seems. And yes, it's no fun, but I can't fix that. If they enables user/pw authentication, you could have used your creds in an authinfo file and it would just connect you like you (anyone) want(s). But that's not allowed, only the PKCE authcode scheme.

 

>>> sas = saspy.SASsession(cfgname='vft', authcode='VhZSA1xZVOskqT8aMWeu4gMEyGO7ZEiq')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/tom/github/saspy/saspy/sasbase.py", line 598, in __init__
self._io = SASsessionHTTP(sascfgname=self.sascfg.name, sb=self, **kwargs)
File "/opt/tom/github/saspy/saspy/sasiohttp.py", line 751, in __init__
self.sascfg = SASconfigHTTP(self, **kwargs)
File "/opt/tom/github/saspy/saspy/sasiohttp.py", line 518, in __init__
js = self._authenticate(user, pw, authcode, client_id, client_secret, jwt, cv)
File "/opt/tom/github/saspy/saspy/sasiohttp.py", line 623, in _authenticate
raise SASHTTPauthenticateError(msg)
saspy.sasexceptions.SASHTTPauthenticateError: Failure in GET AuthToken.
A PKCE URL is configured to be used to acquire an authcode with is system, but a non-PKCE authcode was passed in.
Failure in GET AuthToken.
>>> sas = saspy.SASsession(cfgname='vft', authcode='IOBhsXdPFv4P1LvWUZcFLqCAZKgCNzzN')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/tom/github/saspy/saspy/sasbase.py", line 598, in __init__
self._io = SASsessionHTTP(sascfgname=self.sascfg.name, sb=self, **kwargs)
File "/opt/tom/github/saspy/saspy/sasiohttp.py", line 751, in __init__
self.sascfg = SASconfigHTTP(self, **kwargs)
File "/opt/tom/github/saspy/saspy/sasiohttp.py", line 518, in __init__
js = self._authenticate(user, pw, authcode, client_id, client_secret, jwt, cv)
File "/opt/tom/github/saspy/saspy/sasiohttp.py", line 623, in _authenticate
raise SASHTTPauthenticateError(msg)
saspy.sasexceptions.SASHTTPauthenticateError: Failure in GET AuthToken.
A PKCE URL is configured to be used to acquire an authcode with is system, but a non-PKCE authcode was passed in.
Failure in GET AuthToken.
>>>

navdeepk
Fluorite | Level 6

Okay Got it. Thanks for the clarification guys.

navdeepk
Fluorite | Level 6

Hi, I am trying to read a file from my jupyter notebook how do I send this file or is there any way to read file (either from local or from was drive). Can someone provide me a code snippet and how to do it. 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Discussion stats
  • 23 replies
  • 1222 views
  • 2 likes
  • 4 in conversation