Aug-17-2021, 01:01 PM
(This post was last modified: Aug-17-2021, 01:01 PM by wardancer84.)
hi all,
I got the error "TypeError: missing 3 required positional arguments:". I am aware what this usually means, but in that case...not.
Here is the code, just a simple udp server.
wbr
chris
I got the error "TypeError: missing 3 required positional arguments:". I am aware what this usually means, but in that case...not.
Here is the code, just a simple udp server.
class AIX_REGISTRY_UDPRequestHandler(socketserver.DatagramRequestHandler): def handle(self): r = self.open_db_connection(**db_config) c = r[0] cur = r[1] for line in self.rfile: data = line.strip() data = data.decode('utf-8') cur_thread = threading.current_thread() logger.debug("Thread: {} - Message:{}".format(cur_thread.name, data)) version, node_name, attrib_name, value = data.split("|") nodes = self.reload_nodes(cur) attribs = self.reload_attribs(cur) sql = "INSERT INTO entries VALUES (DEFAULT, %d, %d, '%s', DEFAULT)" % ( self.get_or_create_node_id(node_name,c,cur,nodes), self.get_or_create_attrib_id(attrib_name,c,cur,attribs), value, ) try: cur.execute(sql) c.commit() except db.MySQLError as e: logger.error("Something went wrong during db interaction: {}".format(e)) finally: if cur is not None: cur.close() if c is not None: c.close() def open_db_connection(self,**arg): """Connect to MySQL Database""" try: c = db.connect(**arg) cur = c.cursor() #logger.info("Connection to db opened successfully.") return [c, cur] except db.MySQLError as e: logger.error("Error while trying to connect to db {}".format(e)) def reload_nodes(self,cur): sql = "SELECT name,id from nodes" row = cur.execute(sql) result = cur.fetchall() return dict(result) def reload_attribs(self,cur): sql = "SELECT name,id from attribs" row = cur.execute(sql) result = cur.fetchall() return dict(result) def get_or_create_node_id(self,node_name,c,cur,nodes): if node_name in nodes: print ("%s found in dict, has id %s" % ( node_name, nodes[node_name] )) return int(nodes[node_name]) else: print("creating new node entry ..") sql = "INSERT INTO nodes VALUES (DEFAULT, '%s')" % (node_name) cur.execute(sql) c.commit() return self.get_or_create_node_id(node_name) def get_or_create_attrib_id(self,attrib_name,c,cur,attribs): if attrib_name in attribs: print ("%s found in dict, has id %s" % ( attrib_name, attribs[attrib_name] )) return int(attribs[attrib_name]) else: print("creating new attrib entry ..") sql = "INSERT INTO attribs VALUES (DEFAULT, '%s', DEFAULT, DEFAULT)" % (attrib_name) cur.execute(sql) c.commit() return self.get_or_create_attrib_id(attrib_name)traceback:
creating new node entry .. ---------------------------------------- Exception happened during processing of request from ('172.17.10.20', 41963) Traceback (most recent call last): File "/opt/freeware/lib64/python3.7/socketserver.py", line 650, in process_request_thread self.finish_request(request, client_address) File "/opt/freeware/lib64/python3.7/socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) File "/opt/freeware/lib64/python3.7/socketserver.py", line 720, in __init__ self.handle() File "./aix_reg_server.py_needs_rework", line 61, in handle self.get_or_create_node_id(node_name,c,cur,nodes), File "./aix_reg_server.py_needs_rework", line 108, in get_or_create_node_id return self.get_or_create_node_id(node_name) TypeError: get_or_create_node_id() missing 3 required positional arguments: 'c', 'cur', and 'nodes'the funny thing is the are arguments are clearly passed to function self.get_or_create_node_id. beside that, it seems it iterates over the arguments list somehow, as 4 entries instead of 1 are created in the database.
MariaDB [aix_registry]> select * from nodes where name like '%AIXTESTLPAR%'; +------+---------------+ | id | name | +------+---------------+ | 2219 | AIXTESTLPAR01 | | 2220 | AIXTESTLPAR01 | | 2221 | AIXTESTLPAR01 | | 2222 | AIXTESTLPAR01 | +------+---------------+ 4 rows in set (0.001 sec)any ideas?
wbr
chris