Closed DmitryShS closed 1 year ago
The | jq '.'
part at the end is the problem. If you remove it
curl -s -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ http://netbox/api/ipam/prefixes/ \ --data '{"prefix": "192.0.2.0/24", "site": 6}'
the command converts just fine:
import os
import requests
headers = {
'Authorization': 'Token ' + os.getenv('TOKEN', ''),
# Already added when you pass json=
# 'Content-Type': 'application/json',
}
json_data = {
'prefix': '192.0.2.0/24',
'site': 6,
}
response = requests.post('http://netbox/api/ipam/prefixes/', headers=headers, json=json_data)
You are piping the curl command's output to jq
, we haven't implemented this because you could have a long chain of commands, like
foo | bar | baz | curl example.com | jq
so we have to search the pipeline for the curl command, and what do we do if there's more than one? But I guess we'll just take the first one and ignore the rest of the pipeline. In the future we could also set stdin/stdout to run those commands in the Python as well.