ERROR while updating Spreadsheet using python, Google Seets API, v4: got multiple values for argument ‘range’

I am trying to update a whole spreadsheet using Python, Google Seets API, v4.

I Made a function based on the API to update the database but is giving me the following error:

TypeError: update_values() got multiple values for argument 'range'

The functions are structured in the following way:

def update_values(self, range, values):
    '''
    documentation: https://developers.google.com/sheets/api/guides/values
    values = [
        [
            # Cell values ...
        ],
        # Additional rows ...
    ]
    '''
    body = {
        'values': values
    }
    result = self.service.spreadsheets().values().update(
        spreadsheetId=self.sheet_id,
        range=range,
        valueInputOption='USER_ENTERED',
        body=body).execute()
    print('{0} cells updated.'.format(result.get('updatedCells')))

The execution function is the following:

def update(self,values):
    pprint(self.SHEET_NAME[1])
    self.gsheets.update_values(self,
                               range='{}!A1:AD2000'.format(self.SHEET_NAME[1]),
                               values=values
                               )

Additional data to understand the code:

SHEET_NAME[1]='sheet_x'

gsheets.update_values is the first function update_values() in the class gsheets

range='{}!A1:AD2000'.format(self.SHEET_NAME[1]

Answer

It looks like update_values is a method and you have an instance of its class in self.gsheets. Python adds self automatically when an instance method is called. When you call update_values(self, range=..., ...) that self you put in is actually the second parameter “range”. Just leave that parameter out.

self.gsheets.update_values(range='{}!A1:AD2000'.format(self.SHEET_NAME[1]),
                           values=values
                           )