This is the follow up of Import Modules in Nifi ExecuteScript
I am new to python as well as nifi. I am trying to execute my python script in ExecuteScript processor.
I want to access a server. so i used paramiko client. But when i run the processor, it shows "Import error No module named constant_time" at line session.write(). Though i have this constant_time.py under "/usr/local/lib/python2.7/dist-packages/ "
I have also the path "/usr/local/lib/python2.7/dist-packages/ " in sys.path. I have also given this path in the "Module Directory" property.
This is my code:
import json, pysftp, paramiko
import java.io
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
class ModJSON(StreamCallback):
def __init__(self):
pass
def process(self, inputStream, outputStream):
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
inputText = text.rstrip('\r\n')
json_content = json.loads(inputText)
body = ''
try:
body = json_content['id']['body']
body_encoded = body.encode('utf-8')
except (KeyError,TypeError,ValueError):
body_encoded = ''
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.load_system_host_keys()
ssh_client.connect('server', username='xxx', password='xxxx')
sftp_client = ssh_client.open_sftp()
text_file = sftp_client.open ('/doc/body.txt', 'w')
text_file.write("%s"%body_encoded)
text_file.close()
outputStream.write(bytearray(json.dumps(body, indent=4).encode('utf-8')))
flowFile = session.get()
if (flowFile != None):
flowFile = session.write(flowFile, ModJSON())
flowFile = session.putAttribute(flowFile, "filename", flowFile.getAttribute('filename').split('.')[0]+'_translated.json')
session.transfer(flowFile, REL_SUCCESS)
Any help would be appreciated.

As explained by Matt Burgess in this answer, the
ExecuteScriptprocessor uses Jython, not Python, so compiled modules are not available. There is ongoing discussion of how/if to add this feature.