wsadmin with jython script gives error AttributeError: 'javapackage' object has no attribute 'SEC_SEGMENT' - jython

I am running a jython script with wsadmin commands. It was running fine, until in a new unix env, it stopped working with following error:
AttributeError: 'javapackage' object has no attribute 'SEC_SEGMENT'
my test script looks like this:
#!/usr/bin/python
properties_file_path=sys.argv[0]
sys.path.append(properties_file_path)
import config
import ast
import datetime
start_time=datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
print(start_time+"-Starting execution of script test.py")
new_domain=config.SEC_SEGMENT['new_domain']
print("new domain: "+new_domain)
my config properties, config.py:
SEC_SEGMENT = {
'new_domain': 'Domain2',# New Security Domain
}
in other environments its working fine. Is it a library issue?

Issue is resolved. There was a folder with the same name 'config' as properties file 'config.py' , under same parent directory.
Due to this naming conflict of files, was getting above issue. Issue was resolved by renaming the 'config' folder

Related

pyinstaller-ModuleNotFoundError, How to incl module which added manually by __init__.py in pyinstaller

I have my_ui.py and resources_rc.py are automatically generated from a QT GUI designer.
I can run my_ui.py using python my_ui.py.
This is my-module structure
\my-module
\__init__.py
\my_ui.py
\resouces_rc.py
Content of init.py. resource_rc will be imported and later used inside my_ui.py
from my-module import resources_rc
sys.modules['resource_rc'] = resources_rc
pyinstaller command:
pyinstaller --paths=resources_rc.py myui.py --onefile
I got an error message when running ./dist/my_ui
ModuleNotFoundError: No module named 'resources_rc'
I have tried to run pyinstalled outside my-module directory and still i get this error message.
Any idea how to solve this problem? Many thanks.

ImportError: cannot import name 'IEX_CLOUD_API_TOKEN' from 'secrets'

I'm facing the above error when I try to execute the following code:
from secrets import IEX_CLOUD_API_TOKEN
I tried using '.secrets' instead of 'secrets' but that gives the ModuleNotFoundError.
It's not a problem with the secrets library or anything of such kind.
It's just that after uploading secrets.py to the working directory, restart the kernel in your jupyter notebook.
Code shall run !!

PixiJS for Haxe won't import - Type Not Found error in IntelliJ

I'm trying to run the most basic PixiJS for Haxe sample program, but IntelliJ gives a Type Not Found error.
The failing code:
package ;
import pixi.core.Application;
The error message:
Main.hx:3: characters 7-28 : Type not found : pixi.core.Application
I think the issue is PixiJS-specific, as when I follow the same install-and-import steps for other Haxe modules (eg flambe, flixel) they behave as expected. I've tried with both 4.7.1 and 4.5.5, and as both global and project-specific libraries (separately).
(I hybridized several screenshots to save space)
When running from the console, using:
> haxe -main Main -lib pixijs -js output.js
Everything seems to compile (running the compiled code results in a PIXI is not defined error which is a seperate issue).
UPDATE 1, how I'm adding the dependency:
After executing haxelib install pixijs, I follow these steps:
UDPATE 2, the config being run:
If you can't get it working in the dependencies section you could try adding the haxelibs pixijs externs src/ folder as an additional sources root in Project Structure -> Modules -> (module name) -> Sources. That's how it worked for me:

Geb/Spock Error- No reports dir has been configured, you need to set in the config file or via the build adapter

I have trouble running my functional test from IntelliJ IDE. When I run the functional test, I got the following error message:
java.lang.IllegalStateException: No reports dir has been configured, you need to set in the config file or via the build adapter.
at geb.Browser.getReportGroupDir(Browser.groovy:899)
at geb.Browser.cleanReportGroupDir(Browser.groovy:932)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at geb.spock.GebReportingSpec.setupSpec(GebReportingSpec.groovy:37)
Based on my research, all I need to do is to add the following code in GebConfig.groovy:
reportsDir = new File("target/runtime_reports_dir")
I added the line to GebConfig.groovy and rebuild the project, but still running into the same issue. Is there any other fix to this error?
Adding reportsDir = 'target/geb-reports' to your GebConfig shoud fix this, can you show me your GebConfig file?
There is also another fix for it, your test class extends GebReportingSpec, you can chage it to GebSpec and it should also work.
I had this same issue, while having the reportsDir correctly configured in the GebConfig
Adding the resources folder (where my GebConfig is located) as "Test Sources Root" did the trick for me
To mark the folder as "Test Sources Root":
Right click in the folder
Mark Directory as
Test Sources Root
Happy testing!

Jython does not resolve python imports from bundled Lib files/folders on Weblogic 10.3.5

I am new to Jython and Python, trying to build a prototype that makes use of Python code to be called from within Java. The code I am developing works in Jetty and in standalone mode (running java -jar from the command line), but not when deployed to weblogic.
How can I make weblogic(10.3.5) server/Jython recognize the Lib folder within jython-standalone-2.5.4-rc1.jar?
My Java code uses the JythonObjectFactory to invoke python modules as outlined in the Jython book:
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
The Python modules are using external libraries like csv, logging etc. that are not packaged with jython.jar, hence I am using jython-standalone jar.
The java code includes an interface that would define the class type of the first invoked py module from within java. The interface and the input and output (to python modules) type classes are in a package structure as com.abc.xpackage. and the py modules exist at the root of this package. A controller layer calls the objectfactory and in turn executes the python code thus:
JythonObjectFactory calFactory = new JythonObjectFactory(CalcType.class, "Calculate", "Calculate");
CalcType engine = (CalcType)calFactory.createObject();
output = engine.execute(input);
The entire code is bundled as a jar file which would become part of a web application deployed on weblogic. The code was compiled with maven (with jython dependencies included in the repository) and runs fine on the included Jetty runtime within eclipse.
When deployed on weblogic, however, I get a "ImportError: no module named csv" error.
To analyze what is happening, I tried printing the Jython system state path on weblogic and the standalone environment/Jetty. What I found is,
on Jetty, the system path consists of the following:
C:\.m2\repo\org\python\jython\jython-standalone-2.5.3-rc1.jar\Lib, ____classpath__, ____pyclasspath__
on Weblogic, printing the system path by default shows the following:
____classpath__, ____pyclasspath__
I tried forcing the inclusion of the missing path using the code as follows:
public JythonObjectFactory(PySystemState state, Class interfaceType, String moduleName, String className) {
String pathToAppend = new File(state.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getAbsolutePath()+"\\Lib";
state.path.insert(0, new PyString(pathToAppend));
state.path.append(new PyString(pathToAppend));
System.out.println("Jython sys path: "+state.path);
Please note, I prepended as well as appended the path in different trials. The sys path on weblogic now displays the following:
Jython sys path: ['C:\\wldomain\\wls135\\servers\\cgServer\\tmp\\app-1\\war\\WEB-INF\\lib\\jython-standalone-2.5.4-rc1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\wldomain\\wls135\\servers\\cgServer\\tmp\\app-1\\war\\WEB-INF\\lib\\jython-standalone-2.5.4-rc1.jar\\Lib']
I am still getting ImportError despite this forcing of sys path. Please help why this works in a local environment, and not on weblogic, and if there is any configuration I am missing. Apologize for the rambling long post, I did not know how to explain the problem better. I will try and include any code/artifacts as needed.
Based on a comment(by Lassi) on the blog post below:
http://www.petervannes.nl/files/e1c3c56d15d25dcfd4adb5397a9ef71e-53.php
The jython issue was resolved after explicitly adding the Lib folder python.path to the weblogic startup script as a JAVA_OPTION.
In my case I added the exploded Lib folder to the domain server lib, but based on my test this works also from within the jython jar. Both the following JAVA_OPTIONS worked:
-Dpython.path=C:\wldomain\wls135\lib\Lib
-Dpython.path=C:\wldomain\wls135\lib\jython-standalone-2.5.4-rc1.jar\Lib
The programmatic way of sys.path.append worked for the local environment(jetty) but did not seem to work for weblogic.