Trying to get HTTP.sendHttpPutRequest to work in jython

From an old thread …

Old thread, so maybe this is solved elsewhere, but after a few hours of searching I give up:

I am trying to send a HTTP.sendHttpPutRequest from OH3 jython with json data and Authorization …

I’ve tried many iterations, but here is one:

    uri = "http://openhabian.local:8080/rest/things/zwave:device:0d28f614c7:node8/config"
    data = {
     'key': 'value', 
    auth = {'Authorization' : 'Bearer <mytoken>'}
    content = {'content-type' : 'application/json'}

    HTTP.sendHttpPutRequest(uri, str(content),str(data),auth, 10000)

I get the following error:

2021-10-07 14:31:35.304 [WARN ] [s.impl.WebApplicationExceptionMapper] - HTTP 415 Unsupported Media Type

Is there a simple example to follow?

My curl is working fine, so if I could just get the values into the right format that the HTTP requests wants it would work …

Well, I found the problem … in this case the “content” should just be the content as in ‘application/json’

So just saying:

content = ‘application/json’

Fixed it … :upside_down_face: :roll_eyes:

1 Like