0
实验软件sacred在没有MongoDB的情况下运行,配置为mongo-observer。当它试图写入MongoDB的设置,这个失败,创建文件/tmp/sacred_mongo_fail__eErwU.pickle
,与消息如何导入pickle文件,如果神圣无法连接到MongoDB
Warning: saving to MongoDB failed! Stored experiment entry in /tmp/sacred_mongo_fail__eErwU.pickle
Traceback (most recent calls WITHOUT Sacred internals):
File "/usr/local/lib/python2.7/dist-packages/sacred/observers/mongo.py", line 127, in started_event
self.run_entry[experiment][sources] = self.save_sources(ex_info)
File "/usr/local/lib/python2.7/dist-packages/sacred/observers/mongo.py", line 239, in save_sources
file = self.fs.find_one({filename: abs_path, md5: md5})
File "/usr/local/lib/python2.7/dist-packages/gridfs/__init__.py", line 261, in find_one
for f in self.find(filter, *args, **kwargs):
File "/usr/local/lib/python2.7/dist-packages/gridfs/grid_file.py", line 658, in next
next_file = super(GridOutCursor, self).next()
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 1114, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 1036, in _refresh
self.__collation))
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 873, in __send_message
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 888, in _send_message_with_response
server = topology.select_server(selector)
File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 214, in select_server
address))
File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 189, in select_servers
self._error_message(selector))
ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
这怎么泡菜文件手动导入到MongoDB的?
我觉得这个答案在正确的轨道上,但它并没有为我工作。对于初学者来说,我在pickle文件中的实验已经有了'_id'字段,并且open命令需要'rb'参数在python3中以二进制形式打开......但即使如此,即使insert_one命令没有返回一个错误,它并不实际更新数据库中的(现有)记录。有任何想法吗? – clemej
@clemej:如果'_id'已经存在,你可以'find_one_and_update'。请参阅https://stackoverflow.com/a/46608956/1587329等。 –