Search code examples
pythonlinode

I don't understand this Python TypeError


I am trying to use the Linode API along with this linode-python SDK to manage my Linode servers. However, I'm getting a TypeError I don't understand when I run the linode-disk-list() command.

This is how the linode-python API defines the method I'm calling. As you can see, a LinodeID is required.

@__api_request(required=['LinodeID'],
                 returns=[{u'CREATE_DT': u'YYYY-MM-DD hh:mm:ss.0',
                           u'DISKID': 'Disk ID',
                           u'ISREADONLY': '0 or 1',
                           u'LABEL': 'Disk label',
                           u'LINODEID': 'Linode ID',
                           u'SIZE': 'Size of disk (MB)',
                           u'STATUS': 'Status flag',
                           u'TYPE': "in ['ext3', 'swap', 'raw']",
                           u'UPDATE_DT': u'YYYY-MM-DD hh:mm:ss.0'}])
  def linode_disk_list(self, request):
    """Lists all disk images associated with a Linode."""
    pass

My code creates an instance of the Linode Python API per the SDK's instructions and then calls the linode_disk_list method:

from linode import api as linode_api

api = linode_api.Api(<my_api_key>)
linode_id = 1800300
disks = api.linode_disk_list(linode_id)

My code generates this error:

TypeError: wrapper() takes exactly 1 argument (2 given)

I know I'm creating the api instance correctly as I'm using it to successfully call the linode_ip_list method prior to calling the disk list method.

Just to see what happens, if I don't provide the linode_id argument, I get this error:

linode.api.MissingRequiredArgument: 'LinodeID'

If I call the method with a linode ID, the error says I'm giving it two arguments. But if I don't give it any arguments, it says I'm missing an argument. At this point, I'm not sure if the LinodeID should be an integer or a string but I get the same error in either case. How do I call this method so that I don't get the TypeError argument?

Thanks!


Solution

  • The @__api_request decorator takes a list for each of its arguments:

    def __api_request(required=[], optional=[], returns=[]):
        """Decorator to define required and optional parameters"""
        for k in required:
          [...]
    

    But, you are passing in an integer

    linode_id = 1800300
    disks = api.linode_disk_list(linode_id)
    

    And you are getting conflicting error message about the amount of parameters because the wrapper() method takes an arbitrary amount of keyword arguments

     def wrapper(self, **kw):