Search code examples
pythonlistfunctionself

missing required positional arguments: Python: self


Getting an error :

TypeError: _get_request() missing 6 required positional arguments: 'id_list', 'id_item', 'to_be_sent', 'open', 'received', and 'sent'

When I am trying to call the function:

def _get_request(self, id: str,
                           id_list: List[str],
                           id_item: List[int],
                           to_be_sent: List[int],
                           open: List[int],
                           received: List[int],
                           sent: List[int]):



    return {
            'id': user_id,
            'num_results': 3,
            'id_list': uniqueVisitId,
            'id_item': id_item,
            'to_be_sent': need_to_be_sent,
            'open': open,
            'received': received,
            'sent': sent
    }

By:

self._get_request(
          {
           'id': 'x',
            'id_list': ['a', 'x'],
            'id_item': [1, 2],
            'to_be_sent': [1, 0],
            'open': [0, 0],
            'received': [0, 0],
            'sent': [0, 0]
          }
     )

Any guess why my function cant recognize the positionial arguments which I am passing over?


Solution

  • Because you are passing a dictionary and not arguments...

    You should pass the arguments in order without Dict syntax:

    self._get_request('x', ['a', 'x'], [1, 2],  [1, 0],   [0, 0],[0, 0], [0, 0])