【问题标题】:Python continue script after failure失败后Python继续脚本
【发布时间】:2015-10-08 00:50:51
【问题描述】:

我正在为 Atlassian 的 stash 应用程序使用 python api。

脚本无法删除项目,因为它内部有 repos,然后退出。

Traceback (most recent call last):
  File "stash.py", line 38, in <module>
    stash.projects[p["key"]].delete()
  File "<string>", line 2, in delete
  File "/usr/local/lib/python2.7/site-packages/stashy/errors.py", line 46, in ok_or_error
    maybe_throw(response)
  File "/usr/local/lib/python2.7/site-packages/stashy/errors.py", line 40, in maybe_throw
    raise e
stashy.errors.GenericException: 409: {u'errors': [{u'message': u'The project "TEST" cannot be deleted because it has repositories.', u'exceptionName': u'com.atlassian.bitbucket.IntegrityException', u'context': None}]}

是否可以显示错误但继续执行脚本?

【问题讨论】:

标签: python bitbucket-server


【解决方案1】:

在 Python 中称为 try..expect 模式或异常处理

最简单的形式:

try:
    stash.projects[p["key"]].delete()
except Exception as e:
    print(e)

更多信息:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多