如何显示pymongo.errors.OperationFailure详细信息? [英] How to show pymongo.errors.OperationFailure details?

查看:332
本文介绍了如何显示pymongo.errors.OperationFailure详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写入MongoDB时,我在python中遇到pymongo OperationsFailure.除了回溯,是否还有一种方法可以打印出detail或code属性?

I am getting a pymongo OperationsFailure in python when writing to MongoDB. Is there a way to print out the detail or code attribute in addition to the traceback?

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

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

So far I am using:

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

这篇关于如何显示pymongo.errors.OperationFailure详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆