Search code examples
pythonroundingpython-datetime

TypeError: type datetime.datetime doesn't define __round__ method


I'm working on an API with Python. When trying to parse the data that I got from my database, I got this error: TypeError: type datetime.datetime doesn't define __round__ method.

api.py:

response = []
for i in range(len(histTuple)):
        currentTime = histTuple[i][2].replace(microsecond=0)
        currentTime = str(currentTime) + f" GMT{TIMEZONE}"
        response.append({"humidity": round(histTuple[1][i], 1), "celsius": round(histTuple[0][i]), "fahrenheit": round(histTuple[0][i] * 9/5 + 32), "timestamp": currentTime}) # error here

I'm not trying to round a datetime.datetime, and currentTime isn't even a string!


Solution

  • My query was in this format: [(temperature,),(temperature,),(temperature,)]

    So, flipping the indexes, it worked.