- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Issue with ScriptExecute Processor
- Labels:
-
Apache NiFi
Created ‎11-17-2017 02:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI,
I am stuck with the ScriptExecute process.I am running a small code to see how it works.
flowFile = session.get() if flowFile is not None : myAttr = flowFile.getAttribute('payload') session.transfer(flowFile, REL_SUCCESS)
But i get the attached error. It would be great if someone help me.
SJ
Created on ‎11-17-2017 03:35 PM - edited ‎08-17-2019 09:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try to run the below script
flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') session.transfer(flowFile, REL_SUCCESS)
ExecuteScript Configs:-
In addition if you want to add an attribute,
Below script adding attribute named attr value 1 to the flowfile.
flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') flowFile = session.putAttribute( flowFile, 'attr', '1' ) //adding attribute attr with value 1 to the flowfile session.transfer(flowFile, REL_SUCCESS)
Created on ‎11-17-2017 03:35 PM - edited ‎08-17-2019 09:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try to run the below script
flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') session.transfer(flowFile, REL_SUCCESS)
ExecuteScript Configs:-
In addition if you want to add an attribute,
Below script adding attribute named attr value 1 to the flowfile.
flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') flowFile = session.putAttribute( flowFile, 'attr', '1' ) //adding attribute attr with value 1 to the flowfile session.transfer(flowFile, REL_SUCCESS)
Created ‎11-17-2017 05:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Shu,
Thanks alot for your help always. That works
I made the script to decode the payload and would like to add it to flowfile as you mentioned
flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') out=base64.b64decode(myAttr) out1=base64.b16encode(out) flowFile = session.putAttribute( flowFile, 'attr', 'out1' ) session.transfer(flowFile, REL_SUCCESS)
Got the attached error. Any thoughts please.1.png
Created on ‎11-17-2017 06:41 PM - edited ‎08-17-2019 09:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the below script to add the encoded payload attribute to the flow file.
Script:-
import base64 flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') out=base64.b64decode(myAttr) out1=base64.b16encode(out) flowFile = session.putAttribute( flowFile, 'attr', out1) session.transfer(flowFile, REL_SUCCESS)
diff between 'out1',out1
flowFile = session.putAttribute( flowFile, 'attr', 'out1') //script adds attribute attr value as out1(because out1 is in single quotes). if you want to add the out1 actual encoded value we need to use out1 without single quotes.
Here is an example i tried:-
i am having payload attribute value as asdf.
Python shell output:-
>>> import base64 >>> out=base64.b64decode('asdf') >>> out1=base64.b16encode(out) >>> print out1 6AC75F
NiFi Script:-
Output:-
As you can see above payload attribute value is asdf and script attr value is 6AC75F, Python shell output and script outputs are matching.
Created ‎11-19-2017 01:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks shu, really helpful.
