Member since
05-23-2020
5
Posts
0
Kudos Received
0
Solutions
05-25-2020
08:39 PM
I am working on a python script to post messages to a irc chat. From what I understand I need to use session.get() in order to retrieve flowfiles from a queue. I have tried several things but have not been able to retrieve any files from the queue to successfully post. import socket
from org.apache.nifi.processor.io import StreamCallback, InputStreamCallback
class PyStreamCallback(InputStreamCallback):
def __init__(self):
pass
self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server = "irc.freenode.net"
self.channel = ""
self.botnick = ""
self.ircsock.connect((self.server, 6667))
self.ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick + " " + botnick + "\n"))
self.ircsock.send(bytes("NICK "+ botnick +"\n"))
def joinchan(self, chan):
self.ircsock.send(bytes("JOIN "+ chan +"\n"))
ircmsg = ""
while ircmsg.find("End of /NAMES list.") == -1:
self.ircmsg = ircsock.recv(2048)
self.ircmsg = ircmsg.strip('\n\r')
print(ircmsg)
def sendmsg(self, msg, target=self.channel):
self.ircsock.send(bytes("PRIVMSG "+ target +" :"+ msg +"\n"))
flowFile = session.get()
if (flowFile != None):
flowFile = session.read(flowFile,PyStreamCallback())
session.commit()
... View more
Labels:
- Labels:
-
Apache NiFi
05-25-2020
08:25 PM
I first set it up with executestream and was successful in getting it to work. Isn't it better to use invokescript or executescript because then there isn't a need to maintain scripts outside of NiFi? I just thought it would be better to natively pass the flowfile using flowfile = session.get().
... View more
05-23-2020
08:00 PM
I am trying to use the ExecuteScript processor to run a python program that connects to irc and posts messages. I have python3 on my system but when I paste the python code into the ExecuteScript processor I get the following error: Unable to load script: TypeError: str() takes at most 1 arguments (2 given) in <script> at line number 14: javax.script.ScriptException: TypeError: str() takes at most 1 arguments (2 given) in <script> at line number 14 javax.script.ScriptException: AttributeError: 'NoneType' object has no attribute 'strip' in that line of code looks like below: ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick + " " + botnick + "\n", "UTF-8"))
ircmsg = ircmsg.strip('\n\r') in the python script I am pointing to python3 #!/usr/local/bin/python3.7
import socket
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) How can i get the ExecuteScript processor to use python3? I believe the issue is that NiFi is still using python 2.7 in /usr/bin.
... View more
Labels:
- Labels:
-
Apache NiFi