有以下代码。执行起来非常容易,唯一的问题是,我一次输入了11次。因此,当我执行此代码时,它将内容复制到数据库中 11 次。
row 1
row 2
row 3
...
row 11
这就是我尝试输出的内容:
{
'note': '',
'money': 76682.1200000005,
'main': True,
'deleted': False,
'_id': '5e3e2bc4667b8d5fc053e9a1',
'ownerCharacter':
{
'_id': '5e3ddb08667b8d5fc052903d',
'name': 'Name'
},
'bank':
{
'_id': '5b36b968614626df322e5b75',
'imageUrl': 'urlToIMG',
'name': 'Savings Bank Paleto Bay'
},
'bankAccountType':
{
'type': 'private',
'title': '',
'interestRate': 0.01,
'_id': '5b36b968614626df322e5b76',
'name': 'Giro-Konto',
'bank': '5b36b968614626df322e5b75',
'__v': 0
},
'vban': '460907',
'pin': '1234',
'__v': 0
}
这是代码:
def getData():
databaseConn = dbConnect()
cursor = databaseConn.cursor()
delete = "TRUNCATE TABLE bank"
try:
cursor.execute(delete)
databaseConn.commit()
except:
print("Delete error")
money = json.loads(makeRequest("URL", authToken, True).text)
for amount in money:
geld = str(money["money"])
person = money["ownerCharacter"]["name"]
sql = "INSERT INTO bank (menge,name) VALUES (%s,%s)"
val = (geld,person)
try:
cursor.execute(sql, val)
databaseConn.commit()
except:
print("Error Database")
dbClose(databaseConn, cursor)
我只需要输出一次,而不是连续 11 次。我究竟做错了什么?
收到一只叮咚
智慧大石
相关分类