Hi
I’m trying to send an image from Python to openHAB using the REST API and requests.post, but I’m always getting 415: ‘Unsupported Media Type’
I’ve seen a few posts and some code fragments here about this topic but nothing worked, so I wanted to consolidate. Here’s what I’m doing:
import requests
from io import BytesIO
import base64
...
plt.savefig("/tmp/openHAB_WW.jpeg", format="jpeg")
with open("/tmp/openHAB_WW.jpeg", "rb") as image_file:
base64_utf8_str = base64.b64encode(image_file.read())
data = f'data:image/jpeg;base64,{base64_utf8_str}'
headers = { "Content-Type": "image/jpeg" }
response = requests.post(url, headers=headers, data=data)
What’s wrong with that code? BTW: save as png and using image/png doesn’t work either.
I also had a look into API Explorer, there the request body has to be text/plain (drop down with only this entry).