私はデータベースからデータを取り出し、JSON形式に変換してJSON応答を返すメソッドを作成しました。Python ValueError: '辞書更新シーケンス要素#0の長さは4です。 2が必要です '
def getEchoResource(self):
try:
row = self.cursor.execute("SELECT * FROM echo_resource_log WHERE DATE(last_update) = CURDATE();")
if row:
response = app.response_class(response=json.dumps(dict(self.cursor.fetchall())), status=200, mimetype='application/json')
return response
except MySQLdb.Error as e:
logger.error("Error %d: %s" % (e.args[0],e.args[1]))
except Exception, e:
logger.error("Error : ", str(e))
方法は、このエラーメッセージスロー - とValueError:「辞書更新シーケンス要素#0は長さ4を有します。 2が必要とされる」
トレース -
>/app/worker/echo/apps/opsware_flask_rest_app/opsware_flask_rest_app/
updateEchoResource.py(123)getEchoResource()
-> row = self.cursor.execute("SELECT * FROM echo_resource_log WHERE
DATE(last_update) = CURDATE();")
(Pdb) n
>/app/worker/echo/apps/opsware_flask_rest_app/opsware_flask_rest_app/
updateEchoResource.py(124)getEchoResource()
-> if row:
(Pdb) n
>/app/worker/echo/apps/opsware_flask_rest_app/opsware_flask_rest_app/
updateEchoResource.py(125)getEchoResource()
-> response =
app.response_class(response=json.dumps(dict(self.cursor.fetchall())),
status=200, mimetype='application/json')
(Pdb) n
ValueError: 'dictionary update sequence element #0 has length 4; 2 is
required'
>/app/worker/echo/apps/opsware_flask_rest_app/opsware_flask_rest_app/
updateEchoResource.py(125)getEchoResource()
行が返さ -
('n3pvap168', 'X2Linux_NSS', 'Contact does not exist in Contacts table', datetime.datetime(2017, 7, 21, 4, 27, 37))
正確なエラートレースを確認できますか? –
@Wintro元の質問にトレースを追加しました。 –
「カーソル」からレコードを1つ取り出して印刷して、私たちに見せることはできますか? –