user1745178
user1745178

Reputation: 11

Using a python string output in curl

I have this python script

users=['mark','john','steve']

text=''

for user in users:
    text+=str(user + " ")

print(text)

I want to output that string "text" into a curl terminal command.

I tried:

curl -d "@python-scirpt.py" --insecure -i -X POST https://10.10.10.6/hooks/84kk9emcdigz8xta1bykiymn5e

and

curl --insecure -i -X POST -H 'Content-Type: application/json' -d '{"text": 'python /home/scripts/python-script.py'}' https://10.10.10.6/hooks/84kk9emcdigz8xta1bykiymn5e

or without the quotations in the text option

Everything returns this error

{"id":"Unable to parse incoming data","message":"Unable to parse incoming data","detailed_error":"","request_id":"fpnmfds8zifziyc85oe5eyf3pa","status_code":400}

How to approach this ? Any help is appreciated thank you.

another approach would be to curl inside python but would need help in that too. Thank you

Upvotes: 1

Views: 404

Answers (1)

David
David

Reputation: 433

Use command substitution (i.e. $(...)) to make the shell run the python code first.

So

curl -d "$(python-scirpt.py)" --insecure -i -X POST https://10.10.10.6/hooks/84kk9emcdigz8xta1bykiymn5e

Upvotes: 1

Related Questions