[Python] Python Type Error: Class takes 4 positional arguments but 5 were given when sending...

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to make a multiplayer game in PyGame. So far all the Players where pygame.Rect's. However, in order to make the player more flexible I created a player Class:

    import pygame
    from scene import load_player_entry
    import values

    class Player(pygame.Rect):
    def __init__(self, username, color, scene):
    self.name = username
    self.color = color
    self.scene = scene
    super().__init__(load_player_entry(self.scene),
    (values.PLAYER_WIDTH,
    values.PLAYER_HEIGHT))

    def set_scene(self, scene):
    self.scene = scene
    self.x, self.y = load_player_entry(self.scene)


    The Problem is, that when I "pickle" the Object and send it through sockets to another Client I get the following error:

    Exception in thread NoGameName Server:
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1052, in _bootstrap_inner
    self.run()
    File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 989, in run
    self._target(*self._args, **self._kwargs)
    File "(privacy)/server/server.py", line 75, in main
    connection_data = dill.loads(connection.recv(8192))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/dill/_dill.py", line 301, in loads
    return load(file, ignore, **kwds)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/dill/_dill.py", line 287, in load
    return Unpickler(file, ignore=ignore, **kwds).load()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/dill/_dill.py", line 442, in load
    obj = StockUnpickler.load(self)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: Player.__init__() takes 4 positional arguments but 5 were given


    I already tried using normal pickle and dill, both have the same issue. Increasing the buffersize to 8192 doesn't work either.

    How can I fix this problem? Any Help would be appreciated

    Continue reading...

Compartilhe esta Página