Error: $http:baddata Bad JSON Data

Asked

Viewed 387 times

1

I am finishing developing a web application but I have a problem. All my application was developed in Python, Restful, Angularjs and Chartjs. I am importing information from the database via python and saving in a vector according to the code below:

def consumoKwhLampadaData():
fabrica.cursorExecucao.execute("SELECT round(SUM(kwh),2) AS 'Semanal',IF(dayofweek(DATE_FORMAT(`data`, '%y/%m/%d'))<> 1, 'domingo',IF(dayofweek(DATE_FORMAT(`data`, '%y/%m/%d'))<> 2, (......), IF(dayofweek(DATE_FORMAT(`data`, '%y/%m/%d'))<> 7, 'Sabado','Dia da semana nao definido'))))))) FROM energia WHERE Dispositivo NOT IN ('LAM') AND `data` BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() GROUP BY DATE_FORMAT(`data`, '%d/%m')")
resultado = fabrica.cursorExecucao.fetchall()
consumoKwhLampadaData = []
for data_out in resultado:
    consumoKwhLampadaData.append(str(data_out[1]))
return ('%s') % (consumoKwhLampadaData)

I’m having the problem of "$http:baddata Bad JSON Data" at the angle because it is returning the contents of the "Sunday" vector, the vector has other similar data (Monday, Tuesday...), I couldn’t identify what might be happening, can anyone help me? I need the information of the days of the week to be displayed on a graph in HTML. This is Restfull’s code:

@app.route('/consumoKwhLampadaData', methods=['GET'])
def consumoKwhLampadaData():
    return app.response_class(Servico.consumoKwhLampadaData(), mimetype='text/json')
  • 1

    This error indicates that the result is not being issued in JSON format. You could post an example returned by the call to endpoint /consumoKwhLampadaData, Wendell?

  • Hi Erlon, then, when the data is returned from the database, I want him to change the format to string, as well as when I request to fetch the power consumption value, convert to int. In the case of the vector that is giving problem, I believe it is the content of it, since the others are working.

  • This is the part of the code that receives the vector at the angle. function obterConsumoEmKwhDoVentiladorData() {&#xA; service.consumoKwhVentiladorData = [];&#xA; return $http.get(link.host + link.consumoKwhVentiladorData).then(function (resposta) {&#xA; service.consumoKwhVentiladorData = resposta.data; //retorna a reposta direto para o vetor.&#xA; })&#xA; }

  • I’ll make a comment q is not directly linked to this issue, but honestly, I think for python developers your code frightens, I recommend you take a look at PEP8 https://www.python.org/dev/peps/pep-0008/

  • In time: I was the first to edit your msg to try to make it more "palatable", but still totally at odds with PEP8

  • What do you mean: '...due to be returning the contents of the vector "Sunday"...' - for the other days there is no mistake?

  • Sidon, it may be that the python code is not in the best way, but I’m getting the result I need, I’m beginner in python programming. The big issue of my python code posted (part of it) is that I use encapsulation.

  • Daniel, I don’t know exactly why the error occurs, when I wanted to say '...due to be returning the content of the vector "Sunday"...' would be due to the content of the vector being a string. Sunday is in the first position of the vector, due to the error, I believe that the angular does not read the other positions of the vector.

  • Solved that question? Oh, and for people to be notified when you answer them, use @nomedapessoa.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.