我有一個奇怪的問題。我在Excel中創建了一個vba代碼,它調用一個從Excel表單中獲取信息並將其放入數據庫的Python代碼。昨天沒有問題。今天我開始我的電腦,並嘗試在Python文件中的vba代碼和它的錯誤。python與fetchone的Msql連接給出錯誤
錯誤:
testchipnr = TC104
Traceback (most recent call last):
testchipID = 108
File "S:/3 - Technical/13 - Reports & Templates/13 - Description/DescriptionToDatabase/DescriptionToDatabase.py", line 40, in <module>
TestchipID = cursorOpenShark.fetchone()[0] # Fetch a single row using fetchone() method and store the result in a variable., the [0] fetches only 1 value
TypeError: 'NoneType' object has no attribute '__getitem__'
奇怪的是,有在數據庫中的值 - > testchipID ...
我的代碼:當你說
#get the testchipID and the testchipname
testchipNr = sheet.cell(7, 0).value # Get the testchipnr
print "testchipnr = ", testchipNr
queryTestchipID = """SELECT testchipid FROM testchip WHERE nr = '%s'""" %(testchipNr)
cursorOpenShark.execute(queryTestchipID)
print "testchipID = ", cursorOpenShark.fetchone()[0]
TestchipID = cursorOpenShark.fetchone()[0] # Fetch a single row using fetchone() method and store the result in a variable., the [0] fetches only 1 value
但testchipnr似乎是一個數字,你爲什麼把它放在你的查詢中的引號內? ''%s''?只要刪除引號,如果它的整數 - >'%s' – MYGz
嗨,testchipnr不是一個整數。這是像TC104 – VeVi