I am new to python and am trying to write code that connects to a irc server. I am inputing the code into a NiFi ExecuteScript processor and trying to execute. I get the error below, when running it. I am not sure if it's NiFi causing the issue or just the code it's self.
NameError: name 'self' is not defined in at line number 6
import socket
from org.apache.nifi.processor.io import StreamCallback
class PyStreamCallback(StreamCallback):
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 ping(self):
self.ircsock.send(bytes("PONG :pingis\n"))
def sendmsg(self, msg, target=channel):
self.ircsock.send(bytes("PRIVMSG "+ target +" :"+ msg +"\n"))
flowFile = session.get()
if (flowFile != None):
flowFile = session.write(flowFile,PyStreamCallback())
session.transfer(flowFile, REL_SUCCESS)
session.commit()
Your init function is not properly indented
class PyStreamCallback(StreamCallback):
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"))
...
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.