I'm developing an automation script and I'm getting the next error: ImportError: No module named socket in at line number 2
I'm using jython 2.7, maximo 7.6.
Someone knows a workaround? I know that not every package is installed as it were in python and as it seems the socket pckg is one of the not installed...
I was able to view the Maximo contents of the Maximo jython.jar (or any .jar file) by executing the following command as administrator at the command prompt on a Windows server:
assoc .jar=CompressedFolder
With that I was able to locate and browse the Lib folder within the jython.jar on a Windows server Websphere implementation at the following location:
C:\IBM\WebSphere\AppServer\profiles\ctgAppSrv01\installedApps\ctgCell01\MAXIMO.ear\lib\jython.jar\Lib
The socket.py module exists there so it should be possible to use it from within Jython in Maximo. It appears to be a version specifically written for Jython and references the following in the .py file:
https://wiki.python.org/jython/NewSocketModule
In vanilla Maximo 7.6.0 it appears the Jython path does not include the Lib folder of the jython.jar referenced above. You can find details of how to add it to the path programmatically in an automation script here:
Once that is done you should be able to import the socket library and use it in your script for example:
from java.lang import System
import sys
# Required : Appending to sys.path to refer to python libraries
if sys.path.count('__pyclasspath__/Lib') == 1:
service.log('\nPath to /Lib already exists\n')
else :
service.log('\nExtend path to /Lib \n')
sys.path.append('__pyclasspath__/Lib')
import socket
try:
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
service.log('\nsocket created\n')
except socket.error, msg:
service.log('\nFailed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1] + '\n')
Once that is executed you should see similar to the following in the log (provided autoscript logging is functioning):
07 Jun 2020 15:18:04:949 [DEBUG] putting System value <type 'java.lang.System'>
07 Jun 2020 15:18:04:949 [DEBUG] putting sys value <module 'sys' (built-in)>
07 Jun 2020 15:18:04:949 [DEBUG] getting sys
07 Jun 2020 15:18:04:949 [DEBUG] putting socket value <module 'socket' from '__pyclasspath__/Lib/socket.py'>
07 Jun 2020 15:18:04:949 [DEBUG] getting socket
07 Jun 2020 15:18:04:949 [DEBUG] getting socket
07 Jun 2020 15:18:04:949 [DEBUG] getting socket
07 Jun 2020 15:18:04:949 [DEBUG] putting s value <socket._socketobject object at 0x5>
07 Jun 2020 15:18:04:949 [DEBUG] execution completed for cached compiled script MXC_SOCKET for launch point MXC_SOCKET_LP
07 Jun 2020 15:18:04:949 [DEBUG] Path to /Lib already existssocket created