[SOLVED] Python POST request

Post your questions here and we'll all try to help.
Post Reply
mungle
Posts: 8
Joined: Thu Jan 24, 2019 10:00

[SOLVED] Python POST request

Post by mungle »

Hello,
I made a simple script with python to call some clips with a POST request.

Here my code:

Code: Select all

import requests
r = requests.post("http://192.168.0.11:8080/api/v1/composition/layers/1/clips/2/connect")
print(r.status_code, r.reason)
The print output is
204 No Content
but the clip n.2 is not connected.

If I use "select" instead of "connect" it works:

Code: Select all

http://192.168.0.11:8080/api/v1/composition/layers/1/clips/2/select
If I try with the API page it works (where I get the url).

Where's the problem? I'm using python over terminal on a Mac iOS. Thank you
Last edited by mungle on Tue Dec 28, 2021 18:12, edited 1 time in total.

ynohtna
Posts: 5
Joined: Tue Dec 29, 2020 19:46

Re: Python POST request

Post by ynohtna »

I think that endpoint requires the parameter true encoded in the POST body, supplied as the requests.post method call's data or json keyword parameters.

mungle
Posts: 8
Joined: Thu Jan 24, 2019 10:00

Re: Python POST request

Post by mungle »

You were right!

Here a new working code snippet:

Code: Select all

import time
import requests
import json

richiesta = "http://127.0.0.1:8080/api/v1/composition/layers/1/clips/1/connect"
r = requests.post(richiesta, data=json.dumps(True))
print(r.status_code, r.reason, r.request.body)
time.sleep(.1)
r = requests.post(richiesta, data=json.dumps(False))
print(r.status_code, r.reason, r.request.body)

Post Reply