OpenHAB Docker Python Http Request Rule: ImportError: No module named requests

  • Docker openHAB version: 3.3.0

i want to send http request to my influxDb to write new data and got following error:

ImportError: No module named requests

From python script i do following:

from core.rules import rule
from core.triggers import when
from core.log import logging, LOG_PREFIX
from java.time import ZonedDateTime as DateTime
import json
import requests

log = logging.getLogger("{}.dev".format(LOG_PREFIX))

@when("System started")
def Rule_PvSystemStart(event):
    # influxDb client
    token = "XXXXXX"
    org = "XXXXXX"
    bucket = "XXXXXX"
    # init influxDb String
    influxDbString = ""

    resp ="http://influxdb:8086/api/v2/write?org=" + org + "&bucket=" + bucket + "&precision=s", headers = {"Authorization" : "Token " + token, "Content-Type" : "text/plain; charset=utf-8", "Accept" : "application/json"}, data = influxDbString)

Anybody an idea?

Ahhh the python requests module…
I’d suggest either:

  • use the HTTP action
  • use habapp
  • use jsscripting
  • use jruby

In other words, migrate away from jython.

requests is a separate library you have to install. It doesn’t come with Python 2. See Adding python modules to jython

But ultimately, you would be better served in the long run switching to a different rules language. Python 2 is already end of life and the Jython project still looks no closer to releasing a Python 3 two + years after Python 2 reached end of life.

Ok, thx for information.
I think its time to change the scripting language with this rule.