0

にアクセスしているときにこれは私のpythonだけでなく、nifiに新しいですImport Modules in Nifi ExecuteScriptインポートエラーなしモジュールの名前constant_timeサーバー

のフォローアップです。 ExecuteScriptプロセッサでPythonスクリプトを実行しようとしています。

サーバーにアクセスしたいです。私はparamikoクライアントを使用しました。しかし、プロセッサを実行すると、session.write()行に "constant_timeという名前のモジュールがありません"というエラーが表示されます。私は

enter image description here

"/usr/local/lib/python2.7/dist-packages/" の下で、このconstant_time.pyを持っていますが、私はまた、パスを持っている「/usr/local/lib/python2.7/dist-packages/"をsys.pathに追加します。私はまた、このパスを "Module Directory"プロパティに与えました。

これは私のコードです:

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) 

任意の助けをいただければ幸いです。

+0

[Nifi ExecuteScriptでモジュールをインポート]の可能な複製(http://stackoverflow.com/questions/40719469/import-modules-in-nifi-executescript) – Andy

答えて

0

this answerにマットバージェスにより説明したように、ExecuteScriptプロセッサはのJythonを使用しないパイソンので、コンパイルされたモジュールは使用できません。この機能をどのように追加するかについては、現在進行中の議論があります。

+0

はい。この議論では、モジュールのインポート方法について説明しました。 ExecuteScript Processorの "Module Directory"プロパティにlibパスを追加すると言われました。私はまた、それを "モジュールディレクトリ"に追加しました。しかし、まだそれはエラーを示しています。私はそのようなモジュールを輸入することはできないのですか? – vishnu

+0

私はそれが現在のケースだと信じています - マットが書いたように: "[このSO投稿によると](http://stackoverflow.com/questions/29814603/python-import-error-cannot-import-module-named-counter -white-a-so-file)、paramikoはネイティブライブラリを持つCryptoを使用しているため、Jythonでは使用できません([this post](https://funnifi.blogspot.com/2016/03/)の下部を参照)。 runscript-json-to-json-revisited_14.html)を参考にしてください)。 – Andy

+0

ああ! Andyに感謝します。だから、私はサーバーにアクセスするためにインポートできる他のモジュールはありますか?またはExecuteScriptでサーバーにアクセスして作業するための逆も何ですか? – vishnu

関連する問題