私には奇妙な問題があります。私はexcelでvbaコードを作成しました。これはExcelシートから情報を取得してデータベースに格納するPythonコードを呼び出します。昨日は問題ありませんでした。今日私は自分のコンピュータを起動し、vbaコードを試してみたところ、pythonファイルにエラーがありました。python Msqlとfetchoneとの接続にエラーが発生しました
エラー:
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