TypeError:insert_or_replace_entity()至多需要4个参数(给出5个)

问题描述:

我试图使用python将实体存储到azure存储表中。但我有以下错误。TypeError:insert_or_replace_entity()至多需要4个参数(给出5个)

self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task) 
TypeError: insert_or_replace_entity() takes at most 4 arguments (5 given) 

我提供4个参数只进insert_or_replace_entity()功能,但是编译器考虑五,为什么呢?我不明白,请有人帮助我。

我的代码是在这里:提前

#!/usr/bin/env python 

import time 
import csv 
import sys 

from azure.storage.table import TableService, Entity 

class Azure: 

    table_service = '' 
    task = {} 

    PartitionKey = '' 
    RowKey = '' 
    RPI_ID = '' 
     PIC_ID = '' 
    Date = '' 
    Time = '' 
     Temp = '' 


    def openAccount(self): 
     self.table_service = TableService(account_name='<My account name>', account_key='<My key>') 

    def createTable(self): 
     self.table_service.create_table('myDataTable') 

    def setEntity(self, i): 
     task_i = Entity() 
       task_i.PartitionKey = 'A100' 
      task_i.RowKey = str(i) 
     print task_i   

     task_i.RPI_ID = 'A100' 
       task_i.PIC_ID = 'P100' 
       task_i.Date = time.strftime("%d-%m-%Y") 
       task_i.Time = time.strftime("%I:%M") 
       task_i.Temp = '22.05' 

       self.task = task_i; 

     def insertOrReplaceEntity(self, keyVal): 
     self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task) 

data = Azure() 

data.openAccount() 
data.createTable() 

cnt = 0 

while (cnt < 10): 
    data.setEntity(cnt) 
     data.insertOrReplaceEntity(cnt) 
    cnt = cnt + 1 
    time.sleep(1) 

感谢。

insert_or_replace_entity(table_name, entity, timeout=None)https://azure.github.io/azure-storage-python/ref/azure.storage.table.tableservice.html#azure.storage.table.tableservice.TableService.insert_or_replace_entity)实际上有签名:

def insert_or_replace_entity(self, table_name, entity, timeout=None): 

因此,与self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task)你实际上是做一些像insert_or_replace_entity(self, 'myDataTable', 'A100', keyVal, self.task),因此五个参数。

+1

完美的工作。非常感谢。 – rsp