Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KeyError: 2
#4
(Aug-16-2022, 05:17 PM)ibreeden Wrote: Apparently "row" does not contain what you expect. So in such cases always add a print statement just before the line where the error occurs.
print(row)
What does it show?


Furtheron it is good practice to mention the columns you want instead of "select * from ...". Now you choose all columns and only use row[2], row[3] and row[4]. I is better to specify the columns by name so you can be sure you can use row[0], row[1] and row[2]

Quote:{'id': 1, ‘date’: ‘22.05.2022’, ‘product1’: Decimal('0.0'), ‘product2’: Decimal('3.0'), ‘product3’: Decimal('0.0')}
Traceback (most recent call last):
File “/home/pokip/test.py”, line 77, in <module>
print(“{0}”.format(row))
KeyError: 3
Reply


Messages In This Thread
KeyError: 2 - by stsxbel - Aug-16-2022, 04:15 PM
RE: KeyError: 2 - by deanhystad - Aug-16-2022, 05:16 PM
RE: KeyError: 2 - by ibreeden - Aug-16-2022, 05:17 PM
RE: KeyError: 2 - by stsxbel - Aug-16-2022, 05:34 PM
RE: KeyError: 2 - by deanhystad - Aug-16-2022, 05:48 PM
RE: KeyError: 2 - by stsxbel - Aug-16-2022, 05:55 PM
RE: KeyError: 2 - by stsxbel - Aug-16-2022, 06:05 PM
RE: KeyError: 2 - by deanhystad - Aug-16-2022, 06:27 PM
RE: KeyError: 2 - by stsxbel - Aug-16-2022, 06:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020