Rules: actions import problem after OH restart

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Plus Rev 1.3
    • OS: openHABian
    • Java Runtime Environment: Zulu 8.50.0.259-CA-linux_aarch32hf build 1.8.0_272-b17
    • openHAB version: 2.5.10-1
    • Jython-standalone 2.7.0
  • Issue of the topic: after OH restart jython rules are not fire due to ImportError of Mail action which I don’t declare.

I migrated from DSL rules to jython rules. Everything was going excellent, my rules triggered properly, fast, without any errors. To the time I decided to restart OH. Then I got errors:

2020-11-24 23:18:48.147 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/python/personal/AGM.py’: ImportError: cannot import name Mail in at line number 3

Error is for each jython file I have actions import declaration in. File without actions declaration fires as expected and rules are triggered.
The problem is, that I don’t have import declaration for Mail action in my jython file:

from core.rules import rule
from core.triggers import when
from core.actions import ScriptExecution, Ephemeris
from org.joda.time import DateTime

What I’ve done:

  • restart OH several times
  • clear cash
  • update to 2.5.10 (issue started on OH 2.5.9-1 version)

Still the same problem after my each try.
Problem has gone only if I remove actions import declaration from jython file. Than rules fired but they don’t work due to the lack of loaded actions. After returning actions declaration error comes back.
Now I have no idea how to eliminate this error for not declared Mail action. Need help !

When did you last update your helper libraries? Please post the contents of your core.actions.py.

My guess is that you have modified the file and the restart finally loaded the changes.

Hi, my core.actions.py:

import sys
from core import osgi

__all__ = []

OH1_ACTIONS = osgi.find_services("org.openhab.core.scriptengine.action.ActionService", None) or []
OH2_ACTIONS = osgi.find_services("org.eclipse.smarthome.model.script.engine.action.ActionService", None) or []

_MODULE = sys.modules[__name__]

for action in OH1_ACTIONS + OH2_ACTIONS:
    action_class = action.actionClass
    name = str(action_class.simpleName)
    setattr(_MODULE, name, action_class)
    __all__.append(name)

try:
    from org.openhab.core.model.script.actions import Exec
    from org.openhab.core.model.script.actions import HTTP
    from org.openhab.core.model.script.actions import LogAction
    from org.openhab.core.model.script.actions import Ping
    from org.openhab.core.model.script.actions import ScriptExecution
    from org.openhab.core.model.script.actions import Mail
except:
    from org.eclipse.smarthome.model.script.actions import Exec
    from org.eclipse.smarthome.model.script.actions import HTTP
    from org.eclipse.smarthome.model.script.actions import LogAction
    from org.eclipse.smarthome.model.script.actions import Ping
    from org.eclipse.smarthome.model.script.actions import ScriptExecution
    from org.eclipse.smarthome.model.script.actions import Mail

STATIC_IMPORTS = [Exec, HTTP, LogAction, Ping, ScriptExecution, Mail]

for action in STATIC_IMPORTS:
    name = str(action.simpleName)
    setattr(_MODULE, name, action)
    __all__.append(name)

I didn’t changed it, but modification date of this file is defferent then others so it means it is modified. By me ? but how ?
OK, I downloaded original file and put it to core library files and…all is working again. THANK YOU !

1 Like

Glad you got it working again! In the history of the file on GitHub, those lines for Mail have never existed, so it must have come from your side. Manual installations are easy to mess up and hard to keep up to date. There is a beta Jython addon, but that will be obsolete after I push out some addons to the Eclipse IoT Marketplace. They are actually out already, but I need to push an update to the libraries (install the libraries first!).

Thank you once again. Jython rules are much faster and I improved them during migration, so I’m very hapy they works again.
One more question about Jython addon. I’ve installed it yesterday. After restart OH I had one problem, but I think it was not related to this addon. Jython addon is listed in my bundle list and all rules working.
I want to know: should I do something with previous installed Jython and with libraries in automation/lib folder ? I need to remove them ? or leave it as is ?

My error during restart OH (I think not related with Jython addon) :

2020-11-26 00:04:08.605 [ERROR] [ersey.server.ServerRuntime$Responder] - An I/O error has occurred while writing a response message entity to the container output stream.
org.glassfish.jersey.server.internal.process.MappableException: java.lang.IllegalStateException: Could not find an active context for org.glassfish.jersey.process.internal.RequestScoped
	at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:92) ~[?:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130) ~[bundleFile:?]
	at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:711) [bundleFile:?]
	at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444) [bundleFile:?]
	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434) [bundleFile:?]
	at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329) [bundleFile:?]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [bundleFile:?]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [bundleFile:?]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [bundleFile:?]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [bundleFile:?]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [bundleFile:?]
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [bundleFile:?]
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [bundleFile:?]
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [bundleFile:?]
	at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) [bundleFile:?]
	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) [bundleFile:?]
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) [bundleFile:?]
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) [bundleFile:?]
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) [bundleFile:?]
	at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76) [bundleFile:?]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) [bundleFile:9.4.20.v20190813]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [bundleFile:?]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) [bundleFile:9.4.20.v20190813]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [bundleFile:?]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [bundleFile:9.4.20.v20190813]
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [bundleFile:?]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.Server.handle(Server.java:494) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_272]
Caused by: java.lang.IllegalStateException: Could not find an active context for org.glassfish.jersey.process.internal.RequestScoped
	at org.jvnet.hk2.internal.ServiceLocatorImpl._resolveContext(ServiceLocatorImpl.java:2117) ~[?:?]
	at org.jvnet.hk2.internal.ServiceLocatorImpl.access$000(ServiceLocatorImpl.java:122) ~[?:?]
	at org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:182) ~[?:?]
	at org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:178) ~[?:?]
	at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97) ~[bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_272]
	at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154) ~[bundleFile:?]
	at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199) ~[bundleFile:?]
	at org.jvnet.hk2.internal.ServiceLocatorImpl.resolveContext(ServiceLocatorImpl.java:2130) ~[?:?]
	at org.jvnet.hk2.internal.MethodInterceptorImpl.internalInvoke(MethodInterceptorImpl.java:88) ~[?:?]
	at org.jvnet.hk2.internal.MethodInterceptorImpl.invoke(MethodInterceptorImpl.java:125) ~[?:?]
	at org.jvnet.hk2.internal.MethodInterceptorInvocationHandler.invoke(MethodInterceptorInvocationHandler.java:62) ~[?:?]
	at com.sun.proxy.$Proxy173.getBaseUri(Unknown Source) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.internal.item.ItemResource.lambda$0(ItemResource.java:230) ~[?:?]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_272]
	at java.util.HashMap$KeySpliterator.tryAdvance(HashMap.java:1577) ~[?:1.8.0_272]
	at java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:295) ~[?:1.8.0_272]
	at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:207) ~[?:1.8.0_272]
	at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:170) ~[?:1.8.0_272]
	at java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:301) ~[?:1.8.0_272]
	at java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681) ~[?:1.8.0_272]
	at org.eclipse.smarthome.io.rest.Stream2JSONInputStream.fillBuffer(Stream2JSONInputStream.java:93) ~[?:?]
	at org.eclipse.smarthome.io.rest.Stream2JSONInputStream.read(Stream2JSONInputStream.java:69) ~[?:?]
	at java.io.InputStream.read(InputStream.java:179) ~[?:1.8.0_272]
	at java.io.InputStream.read(InputStream.java:101) ~[?:1.8.0_272]
	at org.glassfish.jersey.message.internal.ReaderWriter.writeTo(ReaderWriter.java:115) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider.writeTo(AbstractMessageReaderWriterProvider.java:79) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:105) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:60) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) ~[?:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) ~[?:?]
	... 53 more

That error has nothing to do with Jython. It occasionally happens when using the iOS app or restarting OH with Paper UI open. With Jetty replaced in OH3, this was marked as resolved.

When using the add-on, or the newer add-ons, when they are ready, remove the lines from your EXTRA_JAVA_OPTS, the core and community libraries, and Jython. Leave the personal package for custom libraries. Also, leave the configuration.py, though this will become optional. I just wrote the docs for this last night, so let me know if you need more detail and I’ll get you a copy. The new stuff is getting very close!

Thanks for instuctions. Please send me your docs if you can - always want to learn more.

I hope to have the updates piushed and docs updated before the end of the holiday weekend. If it’s urgent though, I can send a page or two. It’s actually not too easy to read, since it is in reStructuredText.

It is OK, I will wait, no problem.

1 Like