Python Forum
TypeError: missing 3 required positional arguments:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: missing 3 required positional arguments:
#1
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.

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
Reply


Messages In This Thread
TypeError: missing 3 required positional arguments: - by wardancer84 - Aug-17-2021, 01:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: Diagram.render() takes 1 positional argument but 2 were given sachin1361 0 344 Apr-23-2024, 06:39 AM
Last Post: sachin1361
  TypeError: a bytes-like object is required ZeroX 13 5,012 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 2,108 Oct-17-2022, 06:29 PM
Last Post: paulo79
  TypeError: a bytes-like object is required, not 'str' - Help Please. IanJ 3 5,071 Aug-29-2022, 05:53 PM
Last Post: deanhystad
  TypeError: not enough arguments for format string MaartenRo 6 3,124 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  TypeError: missing a required argument: 'y' gible 0 3,084 Dec-15-2021, 02:21 AM
Last Post: gible
  TypeError: run_oracle_job() missing 1 required positional argument: 'connection_strin python_student 1 2,053 Aug-06-2021, 08:05 PM
Last Post: SheeppOSU
  python 3: TypeError: a bytes-like object is required, not 'str' wardancer84 3 6,755 Jul-09-2021, 05:55 PM
Last Post: deanhystad
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 4,322 May-15-2021, 04:15 PM
Last Post: Anldra12
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 5,670 Jan-06-2021, 04:25 PM
Last Post: Insen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020