首页 / PYTHON / 捕获jira-python异常
捕获jira-python异常
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了捕获jira-python异常,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1724字,纯文字阅读大概需要3分钟。
内容图文
![捕获jira-python异常](/upload/InfoBanner/zyjiaocheng/753/95460633bbc4408595b2ffedd885b6d0.jpg)
我试图处理jira-python异常,但我的尝试,除了似乎没有抓住它.我还需要添加更多行才能发布此内容.他们就是那些线条.
try:
new_issue = jira.create_issue(fields=issue_dict)
stdout.write(str(new_issue.id))
except jira.exceptions.JIRAError:
stdout.write("JIRAError")
exit(1)
以下是引发异常的代码:
import json
class JIRAError(Exception):
"""General error raised for all problems in operation of the client."""
def __init__(self, status_code=None, text=None, url=None):
self.status_code = status_code
self.text = text
self.url = url
def __str__(self):
if self.text:
return 'HTTP {0}: "{1}"\n{2}'.format(self.status_code, self.text, self.url)
else:
return 'HTTP {0}: {1}'.format(self.status_code, self.url)
def raise_on_error(r):
if r.status_code >= 400:
error = ''
if r.text:
try:
response = json.loads(r.text)
if 'message' in response:
# JIRA 5.1 errors
error = response['message']
elif 'errorMessages' in response and len(response['errorMessages']) > 0:
# JIRA 5.0.x error messages sometimes come wrapped in this array
# Sometimes this is present but empty
errorMessages = response['errorMessages']
if isinstance(errorMessages, (list, tuple)):
error = errorMessages[0]
else:
error = errorMessages
elif 'errors' in response and len(response['errors']) > 0:
# JIRA 6.x error messages are found in this array.
error = response['errors']
else:
error = r.text
except ValueError:
error = r.text
raise JIRAError(r.status_code, error, r.url)
解决方法:
我知道我没有回答这个问题,但我觉得我需要提醒那些可能会被代码混淆的人(正如我所做的那样)……
也许你正在尝试编写自己的jira-python版本,或者它是旧版本?
在任何情况下,here链接到JIRAError类的jira-python代码
和here代码列表
要从该包中捕获异常,我使用下面的代码
from jira import JIRA, JIRAError
try:
...
except JIRAError as e:
print e.status_code, e.text
内容总结
以上是互联网集市为您收集整理的捕获jira-python异常全部内容,希望文章能够帮你解决捕获jira-python异常所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。