root@678663ace4e6:/opt/stackstorm# cat /opt/stackstorm/packs/tutorial/actions/nasa_apod.py
#!/usr/bin/env python
#
# Description:
# Queries NASA's APOD (Astronomy Picture Of the Day) API to get the link to the picture
# of the day.
#
import argparse
import json
import requests
API_URL = "https://api.nasa.gov/planetary/apod"
DEMO_API_KEY = "DEMO_KEY"
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--date',
help='The date [YYYY-MM-DD] of the APOD image to retrieve.')
parser.add_argument('--hd',
help='Retrieve the high resolution image.',
action='store_true')
parser.add_argument('-a', '--api-key',
help='API key to use for api.nasa.gov.',
default=DEMO_API_KEY)
return parser.parse_args()
def get_apod_metadata(args):
params = {'api_key': args.api_key,
'hd': args.hd}
if args.date is not None:
params['date'] = args.date
response = requests.get(API_URL, params=params)
response.raise_for_status()
data = response.json()
if args.hd:
data['url'] = data['hdurl']
return data
if __name__ == "__main__":
args = parse_args()
metadata = get_apod_metadata(args)
print(metadata['url'])
after i execute command
st2ctl reload --register-actions
root@678663ace4e6:/opt/stackstorm# st2 run tutorial.nasa_apod date="2018-07-04"
.
id: 64784f5648c62a0c92827372
action.ref: tutorial.nasa_apod
context.user: st2admin
parameters:
date: '2018-07-04'
status: failed
start_timestamp: Thu, 01 Jun 2023 07:57:10 UTC
end_timestamp: Thu, 01 Jun 2023 07:57:11 UTC
result:
failed: true
return_code: 127
stderr: "/usr/bin/env: \u2018python\u2019: No such file or directory"
stdout: ''
succeeded: false
so i can debug this cmd output
root@678663ace4e6:/opt/stackstorm# st2 --debug run tutorial.nasa_apod date=2018-07-04
2023-06-01 07:37:10,856 DEBUG - Using cached token from file "/root/.st2/token-st2admin"
# -------- begin 274946770016 request ----------
curl -X GET -H 'User-Agent: python-requests/2.25.1' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'X-Auth-Token: 3ba4ddd2fb7e4079ab57f6603da48a73' http://st2api:9101/actions/tutorial.nasa_apod
# -------- begin 274946770016 response ----------
{"tags":[],"uid":"action:tutorial:nasa_apod","metadata_file":"actions/nasa_apod.yaml","name":"nasa_apod","ref":"tutorial.nasa_apod","description":"copy of etc/nasa_apod.py","enabled":true,"entry_point":"nasa_apod.py","pack":"tutorial","runner_type":"local-shell-script","parameters":{"api_key":{"type":"string"},"hd":{"type":"boolean"},"date":{"type":"string"}},"output_schema":{},"notify":{},"id":"64784811111f929fdacaff10"}
# -------- end 274946770016 response ------------
# -------- begin 274946769632 request ----------
curl -X GET -H 'User-Agent: python-requests/2.25.1' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'X-Auth-Token: 3ba4ddd2fb7e4079ab57f6603da48a73' 'http://st2api:9101/runnertypes/?name=local-shell-script'
# -------- begin 274946769632 response ----------
[{"name":"local-shell-script","description":"A runner to execute local actions as a fixed user.","uid":"runner_type:local-shell-script","enabled":true,"runner_package":"local_runner","runner_module":"local_shell_script_runner","runner_parameters":{"debug":{"description":"Enable runner debug mode.","type":"boolean","required":false,"default":false},"content_version":{"description":"Git revision of the pack content to use for this action execution (git commit sha / tag / branch). Only applies to packs which are git repositories.","type":"string","required":false},"cwd":{"description":"Working directory where the script will be executed in","type":"string"},"env":{"description":"Environment variables which will be available to the script(e.g. key1=val1,key2=val2)","type":"object"},"kwarg_op":{"default":"--","description":"Operator to use in front of keyword args i.e. \"--\" or \"-\".","type":"string"},"sudo":{"default":false,"description":"The command will be executed with sudo.","type":"boolean"},"sudo_password":{"default":null,"description":"Sudo password. To be used when passwordless sudo is not allowed.","type":"string","required":false,"secret":true},"timeout":{"default":60,"description":"Action timeout in seconds. Action will get killed if it doesn't finish in timeout seconds.","type":"integer"}},"output_schema":{},"id":"6474165debf26eb389d0af93"}]
# -------- end 274946769632 response ------------
# -------- begin 274946771072 request ----------
curl -X POST -H 'User-Agent: python-requests/2.25.1' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'X-Auth-Token: 3ba4ddd2fb7e4079ab57f6603da48a73' -H 'content-type: application/json' -H 'Content-Length: 84' --data-binary '{"action": "tutorial.nasa_apod", "parameters": {"date": "2018-07-04"}, "user": null}' http://st2api:9101/executions
# -------- begin 274946771072 response ----------
{"action":{"tags":[],"uid":"action:tutorial:nasa_apod","metadata_file":"actions/nasa_apod.yaml","name":"nasa_apod","ref":"tutorial.nasa_apod","description":"copy of etc/nasa_apod.py","enabled":true,"entry_point":"nasa_apod.py","pack":"tutorial","runner_type":"local-shell-script","parameters":{"api_key":{"type":"string"},"hd":{"type":"boolean"},"date":{"type":"string"}},"output_schema":{},"notify":{},"id":"64784811111f929fdacaff10"},"runner":{"name":"local-shell-script","description":"A runner to execute local actions as a fixed user.","uid":"runner_type:local-shell-script","enabled":true,"runner_package":"local_runner","runner_module":"local_shell_script_runner","runner_parameters":{"debug":{"description":"Enable runner debug mode.","type":"boolean","required":false,"default":false},"content_version":{"description":"Git revision of the pack content to use for this action execution (git commit sha / tag / branch). Only applies to packs which are git repositories.","type":"string","required":false},"cwd":{"description":"Working directory where the script will be executed in","type":"string"},"env":{"description":"Environment variables which will be available to the script(e.g. key1=val1,key2=val2)","type":"object"},"kwarg_op":{"default":"--","description":"Operator to use in front of keyword args i.e. \"--\" or \"-\".","type":"string"},"sudo":{"default":false,"description":"The command will be executed with sudo.","type":"boolean"},"sudo_password":{"default":null,"description":"Sudo password. To be used when passwordless sudo is not allowed.","type":"string","required":false,"secret":true},"timeout":{"default":60,"description":"Action timeout in seconds. Action will get killed if it doesn't finish in timeout seconds.","type":"integer"}},"output_schema":{},"id":"6474165debf26eb389d0af93"},"liveaction":{"action":"tutorial.nasa_apod","action_is_workflow":false,"parameters":{"date":"2018-07-04"},"callback":{},"runner_info":{},"id":"64784aa648c62a0c92827368"},"status":"requested","start_timestamp":"2023-06-01T07:37:10.983767Z","parameters":{"date":"2018-07-04"},"context":{"user":"st2admin","pack":"tutorial"},"log":[{"timestamp":"2023-06-01T07:37:10.998853Z","status":"requested"}],"web_url":"https://d676433a2fb9/#/history/64784aa748c62a0c92827369/general","id":"64784aa748c62a0c92827369"}
# -------- end 274946771072 response ------------
.# -------- begin 274946771072 request ----------
curl -X GET -H 'User-Agent: python-requests/2.25.1' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'X-Auth-Token: 3ba4ddd2fb7e4079ab57f6603da48a73' http://st2api:9101/executions/64784aa748c62a0c92827369
# -------- begin 274946771072 response ----------
{"action":{"tags":[],"uid":"action:tutorial:nasa_apod","metadata_file":"actions/nasa_apod.yaml","name":"nasa_apod","ref":"tutorial.nasa_apod","description":"copy of etc/nasa_apod.py","enabled":true,"entry_point":"nasa_apod.py","pack":"tutorial","runner_type":"local-shell-script","parameters":{"api_key":{"type":"string"},"hd":{"type":"boolean"},"date":{"type":"string"}},"output_schema":{},"notify":{},"id":"64784811111f929fdacaff10"},"runner":{"name":"local-shell-script","description":"A runner to execute local actions as a fixed user.","uid":"runner_type:local-shell-script","enabled":true,"runner_package":"local_runner","runner_module":"local_shell_script_runner","runner_parameters":{"debug":{"description":"Enable runner debug mode.","type":"boolean","required":false,"default":false},"content_version":{"description":"Git revision of the pack content to use for this action execution (git commit sha / tag / branch). Only applies to packs which are git repositories.","type":"string","required":false},"cwd":{"description":"Working directory where the script will be executed in","type":"string"},"env":{"description":"Environment variables which will be available to the script(e.g. key1=val1,key2=val2)","type":"object"},"kwarg_op":{"default":"--","description":"Operator to use in front of keyword args i.e. \"--\" or \"-\".","type":"string"},"sudo":{"default":false,"description":"The command will be executed with sudo.","type":"boolean"},"sudo_password":{"default":null,"description":"Sudo password. To be used when passwordless sudo is not allowed.","type":"string","required":false,"secret":true},"timeout":{"default":60,"description":"Action timeout in seconds. Action will get killed if it doesn't finish in timeout seconds.","type":"integer"}},"output_schema":{},"id":"6474165debf26eb389d0af93"},"liveaction":{"action":"tutorial.nasa_apod","action_is_workflow":false,"parameters":{"date":"2018-07-04"},"callback":{},"runner_info":{"hostname":"22fe5bf776dd","pid":1},"id":"64784aa648c62a0c92827368"},"status":"failed","start_timestamp":"2023-06-01T07:37:10.983767Z","end_timestamp":"2023-06-01T07:37:11.478498Z","parameters":{"date":"2018-07-04"},"result_size":128,"context":{"user":"st2admin","pack":"tutorial"},"log":[{"timestamp":"2023-06-01T07:37:10.998000Z","status":"requested"},{"timestamp":"2023-06-01T07:37:11.159000Z","status":"scheduled"},{"timestamp":"2023-06-01T07:37:11.225000Z","status":"running"},{"timestamp":"2023-06-01T07:37:11.509000Z","status":"failed"}],"web_url":"https://d676433a2fb9/#/history/64784aa748c62a0c92827369/general","id":"64784aa748c62a0c92827369","result":{"failed":true,"succeeded":false,"return_code":127,"stdout":"","stderr":"/usr/bin/env: ‘python’: No such file or directory"},"elapsed_seconds":0.494731}
# -------- end 274946771072 response ------------
id: 64784aa748c62a0c92827369
action.ref: tutorial.nasa_apod
context.user: st2admin
parameters:
date: '2018-07-04'
status: failed
start_timestamp: Thu, 01 Jun 2023 07:37:10 UTC
end_timestamp: Thu, 01 Jun 2023 07:37:11 UTC
result:
failed: true
return_code: 127
stderr: "/usr/bin/env: \u2018python\u2019: No such file or directory"
stdout: ''
succeeded: false
execute .py file is success
is successed
so i flowiing this tutorial i create a py and metadata file
after i execute command
so i can debug this cmd output
how can i do ?