0

when I execute the command:

 curl http://cs-service:5000/swdpconfig/swdp_templateConfigData/robot_framework

the output is:

{
  "adm_ts_path": "/data/ngxp_test_automation/bin/admin",
  "be_ts_path": "/data/ngxp_test_automation/bin/backend",
  "fe_ts_path": "/data/ngxp_test_automation/bin/frontend",
  "ip": "40.124.25.232",
  "password": "Er1c550n@123",
  "port": "22",
  "user": "ngxpcdd"
}

Now I want to use the key-value pairs as parameters in my python script. How can I do that

Vishal Singh
  • 6,014
  • 2
  • 17
  • 33

2 Answers2

0

You could pipe it directly to python if you want it executed in cli, and if not as someone mentioned you can save it as a file and load it in python with json.loads

Here is already answered stackoverflow question that might peak your interest

Pipe output from shell command to a python script

  • that the main question **how to pipe it directly to python?**. – Vishal Singh Mar 17 '21 at 18:26
  • @VishalSingh with a [bash pipe and python script reading stdin ] [https://stackoverflow.com/questions/11109859/pipe-output-from-shell-command-to-a-python-script/11109920] also edited the main answer for visibility – Josip Stjepanovic Mar 17 '21 at 18:28
-1

why would you mix python and curl ... that basically doesnt make much sense ... but you easily can

import subprocess,json
data = json.loads(subprocess.check_output('curl ...'))

it would be a much better idea to just use python (either requests or urllib)

import requests
url = "http://cs-service:5000/swdpconfig/swdp_templateConfigData/robot_framework"
data = requests.get(url).json()

if you wanted to use urllib instead i think its just

import urllib.request, json
data = json.loads(urllib.request.urlopen(urlData).read())
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179