I'm writing a python script that hits an API and then writes various data to a MySQL database.
One of the fields I'm trying to write is a date object, but I keep running into a "TypeError: 'datetime.datetime' object is not iterable" error and can't seem to get past it. I'm convinced it's something really simple, but I can't figure out what.
First, I call the API to get a json object with several dates and metrics in them. Then I loop through the dates and am trying to write them to the DB.
for day in results:
mydate = datetime.datetime.strptime(day['date'], '%Y-%m-%d')
print mydate
date_query = "INSERT INTO sendgrid_stats (date) VALUES (%s)"
cursor.execute(date_query, mydate)
connection.commit()
If you print the date that's attempted to be inserted, it looks like "2015-07-26 00:00:00" (without the quotes).
Does anyone know what I'm doing wrong? My face hurts from banging my head into the keyboard.