When getting results from a mysql database using dict cursor class, the types are converted to python's types and are "included" in the dictionary's values (I'm sorry I don't know how to better word this).
I've looked for examples and I can't seem to see others getting their results in the "format" I do.
This is the result i get after cursor.fetchall():
{
'description': 'Outside',
'date': datetime.datetime(2020, 5, 4, 15, 0),
'temperature': Decimal('14.9'),
'humidity': Decimal('48.0')
}
This is giving me issues when trying to convert the whole dictionary to json at once with json.dumps()
: TypeError: the JSON object must be str, bytes or bytearray, not Decimal
Is there a way for the cursor to return just {'temperature' : 14.9}
as opposed to {'temperature': Decimal('14.9')}
?
Same with the date.
My apologies if I am not including all the necessary information, I'm not sure what other info I could share to help you help me. Please let me know and I'll gladly add it.
To connect and create the cursor I just followed the example on github from pymysql
When opening the connection I'm not passing the charset option, my db is "utf8_general_ci". I tried passing "utf8" and "utf8mb4" and it didn't make a difference.
Thanks in advance.