title: python bson.errors.InvalidDocument: Cannot encode object: datetime.date(2015, 3, 1)
body: <p>I have the following functions:</p>
  
  <pre><code>#  this is in a module called 'dbw_lib'
  def dateTimeOuput(start_days_back, end_days_back):
      start_delta = datetime.timedelta(days=start_days_back)
      end_delta = datetime.timedelta(days=end_days_back)
      start_date = datetime.date.today() - start_delta
      end_date = datetime.date.today() - end_delta
      return start_date, end_date
  
  def dictByDate(start_days, end_days):
      start_date, end_date = dbw_lib.dateTimeOuput(start_days, end_days)
  
      date_string = { "created_at": {"$gte" : start_date, "$lt": end_date }  }
  
      user_id_email_dict = dbw_lib.dbwIdToEmailD(user_coll_obj, date_query = date_string)  # dict of all user ids and emails  
      print user_id_email_dict
      quit()
  </code></pre>
  
  <p>when I run <code>key_dicts = dictByDate(90, 60)</code>, I'm getting the following traceback:</p>
  
  <pre><code>Traceback (most recent call last):
  File "main.py", line 212, in &lt;module&gt;
  program.runProgram()
  File "main.py", line 61, in runProgram
  report.RcreateReport()
  File "filepath/report.py", line 86, in RcreateReport
  key_dicts = dictByDate(90, 60)
  File "filepath/report.py", line 65, in dictByDate
  user_id_email_dict = dbw_lib.dbwIdToEmailD(user_coll_obj, date_query = date_string)  # dict of all user ids and emails  
  File "filepath/dbw_lib.py", line 50, in dbwIdToEmailD
  for pair in id_email_cursor:
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/cursor.py", line 968, in __next__
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/cursor.py", line 905, in _refresh
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/cursor.py", line 812, in __send_message
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/mongo_client.py", line 732, in _send_message_with_response
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/mongo_client.py", line 743, in _reset_on_error
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/server.py", line 85, in send_message_with_response
  File "/Library/Python/2.7/site-packages/pymongo-3.0-py2.7-macosx-10.9-intel.egg/pymongo/message.py", line 107, in get_message
  bson.errors.InvalidDocument: Cannot encode object: datetime.date(2015, 3, 1)
  </code></pre>