写入 MongoDB 时,我在 python 中遇到 pymongo OperationsFailure。除了回溯之外,有没有办法打印出详细信息或代码属性?

另见:http://api.mongodb.org/python/current/api/pymongo/errors.html#pymongo.errors.OperationFailure.details

到目前为止,我正在使用:

try:
  connection.test.foo.find_one()
except pymongo.errors.OperationFailure:
  print "caught"

最佳答案

作品:

try:
    connection.test.foo.find_one()
except pymongo.errors.OperationFailure as e:
    print e.code
    print e.details

关于python - 如何显示 pymongo.errors.OperationFailure 详细信息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28407471/

10-13 09:49