[英]NameError: name 'self' is not defined in <script> at line number 6
I am new to python and am trying to write code that connects to a irc server.我是 python 新手,正在尝试编写连接到 irc 服务器的代码。 I am inputing the code into a NiFi ExecuteScript processor and trying to execute.
我正在将代码输入 NiFi ExecuteScript 处理器并尝试执行。 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.
我不确定是 NiFi 导致了问题还是只是它自己的代码。
NameError: name 'self' is not defined in at line number 6
NameError: name 'self' 未在第 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您的 init 函数没有正确缩进
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"))
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.