Proper call of some REST API methods #windows

Alexander Sevryukov

When trying to modify one of the .py examples, I ran into the fact that r.status_code = 202 returned. Perhaps this happens when calling commands that require some time to execute. For example, here I add Sink T0
        deviceset_index_rx = 1
        deviceset_url = "/ deviceset /% d"% deviceset_index_rx
        r = callAPI (deviceset_url + "/ device", "PUT", None, {"hwType": "HackRF", "tx": 1}, "setup device on Tx device set")
# if r is None:
# exit (-1)
        time.sleep (2)
I had to remove error handling, but add a pause before the next calls. Where can I see how to handle this correctly? I saw something similar in, but there it was somehow completely different.
To apply a preset to T0, I need to add it and install the "hwType": "HackRF" call the PATCH method to the preset as done here ( with the command
    ["/ preset", "PATCH", None, {"deviceSetIndex": 0, "preset": {"groupName": "OM144", "centerFrequency": 145480000, "type": "R", "name": "Rept + Simplex + DV"}}, "load preset on Rx 0"]]? (but "deviceSetIndex": 0, "type": "T"). So far I have failed.

Windows 7, SDRangel 4.5.3

Edouard Griffiths

HTTP code 202 is not an error like any of the 200's range. 
As far as I can see the HTTP code is tested like this: 
"if r.status_code / 100 == 2:"
Depending on the version of Python you may need to force Euclidean division like this:
"if r.status_code // 100 == 2:"

Brgds, Edouard.

Alexander Sevryukov

Thanks, Edouard

if r.status_code // 100 == 2:

It works :)