I am trying to use NiFi ExecuteScript to post messages to an irc chatroom using Python. Am I using the right syntax to pass a flowfile from a queue to the processor? Processor errors out with NameError: global name 'server' is not defined, but I am not positive what's causing it. Everything seems to work until I add the session.get().
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((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=channel):
self.ircsock.send(bytes("PRIVMSG "+ target +" :"+ msg +"\n"))
flowFile = session.get()
if (flowFile != None):
flowFile = session.read(flowFile,PyStreamCallback())
session.commit()
self.ircsock.connect((server, 6667))
should be
self.ircsock.connect((self.server, 6667))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.