labthings / python-labthings

Python implementation of LabThings, based on the Flask microframework
GNU General Public License v3.0
18 stars 2 forks source link

Passing arguments to post requests #299

Closed glyg closed 2 years ago

glyg commented 2 years ago

Hi, I started exploring labthings as a generic instrument interface tool with a toy project controlling a USB camera, see here: https://github.com/centuri-engineering/olf_control - I find it very promising.

There is something I can't get to work though (not sure if this is a bug or me not doing things correctly): I don't understand how to pass the arguments to the post method of an Action with a POST request.

With curl, this as no effect (the default of 20 is used):

curl -X POST localhost:7485/actions/average?averages=10

And in Python with requests this as no effect either:

response = requests.post("http://localhost:7485/actions/average", data={"averages": 5})

The post method is defined here and the corresponding USBCamera method is defined there

The app is started with python app.py in the code linked above.

Any hint appreciated!

Guillaume

glyg commented 2 years ago

My error was to pass data = instead of json = to requests.post, it works nicely with

response = requests.post("http://localhost:7485/actions/average", json={"averages": 5})