Hi, I’m running the latest version of OH3 on Docker.
Migration has not been painless but I was doing fine till yesterday.
I have a rule that is triggered by a sensor state change.
Step 1 : I want to take a snapshot with a cctv cam
Step 2 : I will send the image to another application running on docker.
Step 3 : I will receive results in JSON format.
This is what I have so far:
# imports
from org.slf4j import LoggerFactory
import urllib2
import urllib
import base64
# Start The logger
log = LoggerFactory.getLogger("org.openhab.core.automation.examples")
#take a snapshot
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, "http://192.168.1.99/ISAPI/Streaming/channels/1/picture", "username", "password")
authhandler = urllib2.HTTPDigestAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
res = opener.open("http://192.168.1.99/ISAPI/Streaming/channels/1/picture")
pic = base64.b64encode(res.read())
#(I have saved this "pic" to a file and tested it. I get an base64 encoded image)
#Get the plate
url = 'http://platerecognizer:8080/v1/plate-reader/'
values = {'regions' : 'gr','regions' : 'de','upload': pic}
data = urllib.urlencode(values)
req = urllib2.Request(url)
req.add_data(data)
import socket
# timeout in seconds
timeout = 10
socket.setdefaulttimeout(timeout)
log.info("start0")
z = urllib2.urlopen(req) #<---this is where it all goes to hell...
log.info("stop0")
log.info(str(z.read()))
z = urllib2.urlopen(req)
this is where the problem is, but it is cause by the pic variable
when I try to upload any sting I get a response from the server
{“error”: “base64 content could not be decoded.”}
when I use the variable “pic” the connections just hangs forever without a timeout.
the exact same code works in a simple python script…
my bet is that something is going wrong with the encoding since I had a lot of problems getting this far, (something to do with ascci and utf-8 and java or python2 not liking one of them or something)
I’ve been at it for hours but I’m genuinely stuck. any help would be appreciated