Adding libraries to nxshell Jython?

Started by zshnet, August 17, 2016, 03:20:57 PM

Previous topic - Next topic

zshnet

Hi all,

I'd like to use the python library "requests" with Jython, but I can't seem to find where NetXMS installs it. Is it balled up in the nxshell Jar? Is there a way I could add libraries to Jython? I looked, and apparently requests is compatible with Jython.

Thanks,
Zach

Alex Kirhenshtein

Like any  pure-python library, just add it to search path.

mkdir c:\tmp
cd c:\tmp
git clone git://github.com/kennethreitz/requests.git
java -jar nxshell-2.0.5.jar
Server IP [127.0.0.1]:
Login [admin]:
Password [netxms]:
NetXMS 2.0.5 Interactive Shell
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>> import sys
>>> sys.path.append('c:\\tmp\\requests')
>>> import requests
>>> r = requests.get('https://www.netxms.org/')
<Response [200]>
>>> r.status_code
200
>>> r.headers
{'Keep-Alive': 'timeout=15, max=100', 'Server': 'Apache/2.2.16 (Debian)', 'Connection': 'Keep-Alive', 'Date': 'Wed, 17 Aug 2016 14:06:34 GMT', 'Accept-Ranges': 'bytes', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Content-Length': '3237', 'Content-Type': 'text/html'}

zshnet

Fancy! Thanks for the suggestion. I'll give it a shot.

Thanks,
Zach

zshnet

Worked like a charm! Just had to change something in the python hmac_auth library because Jython is strongly typed, but otherwise it was no sweat.

Thanks again for the help!