I have created a method that fetches the data from the database, converts it into json format and returns the JSON response.
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))
The method throws this error message - ValueError: 'dictionary update sequence element #0 has length 4; 2 is required'
Trace -
>/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()
row returned -
('n3pvap168', 'X2Linux_NSS', 'Contact does not exist in Contacts table', datetime.datetime(2017, 7, 21, 4, 27, 37))