0

Could someone help me with the following:

I have this line that I normally run in terminal:

 path/to/mysh/script.sh PROD generate-ticket username

and it gives me the following output in terminal:

{"user":{"Userid":123,"firstName":"Joe","SecondName":"Doe","loginName":"jdoe"},"accessToken":"1235df6543cggf432sa24"}

I need the 'accessToken' value assigned to python variable.

My code:

import subprocess
import json 

username ='jdoe'

def get_Access_Token(username):
    s = json.loads(subprocess.check_output(['path/to/mysh/script.sh', 'PROD', 'generate-ticket', username]))


print (s['accessToken'])

but it gives me the following error when trying to print my variable:

NameError: name 's' is not defined

Thanks in advance!

1 Answer 1

1

Return the value from the function.

Ex:

import subprocess
import json 

username ='jdoe'

def get_Access_Token(username):
    return json.loads(subprocess.check_output(['path/to/mysh/script.sh', 'PROD', 'generate-ticket', username]))['accessToken']

print (get_Access_Token(username))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.