我正在尝试使用python将实体存储到azure存储表中。但我得到了以下错误。
self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task)
TypeError: insert_or_replace_entity() takes at most 4 arguments (5 given)
我只在 insert_or_replace_entity()函数中提供 4个参数,但编译器考虑了五个,为什么?我不明白,请有人帮助我。
我的代码在这里:
#!/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)
提前致谢。
答案 0 :(得分: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)
之类的事情,因此有五个论点。