phipse / complexlab_ai

1 stars 1 forks source link

bson.errors.InvalidDocument: Cannot encode object: datetime.date(1985, 4, 8) #14

Open pschwede opened 11 years ago

pschwede commented 11 years ago

I call src/main.py data data/tasks/test_task.json and sometimes get this:

done
/usr/lib64/python2.7/site-packages/pymongo/collection.py:359: RuntimeWarning: couldn't encode - reloading python modules and trying again. if you see this without getting an InvalidDocument exception please see http://api.mongodb.org/python/current/faq.html#does-pymongo-work-with-mod-wsgi
  continue_on_error, self.__uuid_subtype), safe)
Traceback (most recent call last):
  File "src/main.py", line 192, in <module>
    sys.exit(__cli_main())
  File "src/main.py", line 183, in __cli_main
    extract(args, task, crawler_list)
  File "src/main.py", line 79, in extract
    extractor_stream(feature_extractor, crawler_list)
  File "src/main.py", line 48, in extractor_stream
    summ.process(extractResult.itervalues().next())
  File "/home/peter/Documents/Informatik-Studium/09/Komplexpraktikum Intelligente Systeme/complexlab_ai/src/summarist/__init__.py", line 23, in process
    meta.save()
  File "/home/peter/Documents/Informatik-Studium/09/Komplexpraktikum Intelligente Systeme/complexlab_ai/src/summarist/meta.py", line 28, in save
    self.db.meta.save(self.data)
  File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 268, in save
    return self.insert(to_save, manipulate, safe, check_keys, **kwargs)
  File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 359, in insert
    continue_on_error, self.__uuid_subtype), safe)
bson.errors.InvalidDocument: Cannot encode object: datetime.date(1985, 4, 8)
RussellOsiemo commented 1 year ago

Im having the same issue in my notebook where I have a list of dictionaries and in the dictionary, the problem is : mylist = [{'trans_time': datetime.date(2021, 1, 1),{'trans_time': datetime.date(2021, 1, 1),....}....}]

InvalidDocument Traceback (most recent call last) Cell In[47], line 1 ----> 1 collection.insert_many(c360_list)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py:770, in Collection.insert_many(self, documents, ordered, bypass_document_validation, session) 768 blk = _Bulk(self, ordered, bypass_document_validation) 769 blk.ops = [doc for doc in gen()] --> 770 blk.execute(write_concern, session=session) 771 return InsertManyResult(inserted_ids, write_concern.acknowledged)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\bulk.py:529, in _Bulk.execute(self, write_concern, session) 527 self.execute_no_results(sock_info, generator) 528 else: --> 529 return self.execute_command(generator, write_concern, session)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\bulk.py:360, in _Bulk.execute_command(self, generator, write_concern, session) 358 client = self.collection.database.client 359 with client._tmp_session(session) as s: --> 360 client._retry_with_session( 361 self.is_retryable, retryable_bulk, s, self) 363 if full_result["writeErrors"] or full_result["writeConcernErrors"]: 364 _raise_bulk_write_error(full_result)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1438, in MongoClient._retry_with_session(self, retryable, func, session, bulk) 1429 """Execute an operation with at most one consecutive retries 1430 1431 Returns func()'s return value on success. On error retries the same (...) 1434 Re-raises any exception thrown by func(). 1435 """ 1436 retryable = (retryable and self.retry_writes 1437 and session and not session.in_transaction) -> 1438 return self._retry_internal(retryable, func, session, bulk)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1470, in MongoClient._retry_internal(self, retryable, func, session, bulk) 1468 raise last_error 1469 retryable = False -> 1470 return func(session, sock_info, retryable) 1471 except ServerSelectionTimeoutError: 1472 if is_retrying(): 1473 # The application may think the write was never attempted 1474 # if we raise ServerSelectionTimeoutError on the retry 1475 # attempt. Raise the original exception instead.

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\bulk.py:354, in _Bulk.execute_command..retryable_bulk(session, sock_info, retryable) 353 def retryable_bulk(session, sock_info, retryable): --> 354 self._execute_command( 355 generator, write_concern, session, sock_info, op_id, 356 retryable, full_result)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\bulk.py:310, in _Bulk._execute_command(self, generator, write_concern, session, sock_info, op_id, retryable, full_result) 308 ops = islice(run.ops, run.idx_offset, None) 309 # Run as many ops as possible in one command. --> 310 result, to_send = bwc.execute(ops, client) 312 # Retryable writeConcernErrors halt the execution of this run. 313 wce = result.get('writeConcernError', {})

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\message.py:949, in _BulkWriteContext.execute(self, docs, client) 948 def execute(self, docs, client): --> 949 request_id, msg, to_send = self._batch_command(docs) 950 result = self.write_command(request_id, msg, to_send) 951 client._process_response(result, self.session)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\message.py:941, in _BulkWriteContext._batch_command(self, docs) 939 def _batch_command(self, docs): 940 namespace = self.db_name + '.$cmd' --> 941 request_id, msg, to_send = _do_bulk_write_command( 942 namespace, self.op_type, self.command, docs, self.check_keys, 943 self.codec, self) 944 if not to_send: 945 raise InvalidOperation("cannot do an empty bulk write")

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\message.py:1443, in _do_bulk_write_command(namespace, operation, command, docs, check_keys, opts, ctx) 1441 """Bulk write commands entry point.""" 1442 if ctx.sock_info.max_wire_version > 5: -> 1443 return _do_batched_op_msg( 1444 namespace, operation, command, docs, check_keys, opts, ctx) 1445 return _do_batched_write_command( 1446 namespace, operation, command, docs, check_keys, opts, ctx)

File C:\ProgramData\Anaconda3\lib\site-packages\pymongo\message.py:1368, in _do_batched_op_msg(namespace, operation, command, docs, check_keys, opts, ctx) 1365 if ctx.sock_info.compression_context: 1366 return _batched_op_msg_compressed( 1367 operation, command, docs, check_keys, ack, opts, ctx) -> 1368 return _batched_op_msg( 1369 operation, command, docs, check_keys, ack, opts, ctx)

InvalidDocument: cannot encode object: datetime.date(2021, 1, 1), of type: <class 'datetime.date'>