python - API doesn't accept requests.put HTTP call, JSON formatting -
i'm trying make http call using requests http library python.
i have code:
import requests import json body = json.dumps({"on": "false"}) url = "http://192.168.100.100/api/0000/lights/4/state" r = requests.put(url=url, data=body)
however, api responds with
"error": { "type": 7, "address": "/lights/4/state/on", "description": "invalid value, true }, parameter, on"
i'm not entirely sure problem is, body getting formatted wrong; r.request.body says
{"on": "false"}
when should be
{"on": false}
if take off quotes code get
nameerror: name 'false' not defined
the call works when done in browser, know value correct parameter. how can correctly send call?
try changing body = json.dumps({"on": "false"})
body = json.dumps({"on": false})
notice capitalization on false
in python.
Comments
Post a Comment