分别处理特定(for io)异常(Handle specific (for io) exception separately)
某些IO操作会产生一些错误。 重要的是,它不是一个例外,而是设定。 因此,我们设置了套接字错误,为文件io设置。 如何为不同的io操作处理没有交集的异常组?
例如,
OSError
处理文件io错误和一些(?)套接字错误。我只有一个解决方案:用try-except包装io操作并引发用户定义的异常。
def foo(): try: # some file io except: raise MyFileIOException(reason=sys.exc_info()) try: # some socket io except: raise MySocketIOException(reason=sys.exc_info()) def bar(): try: foo() except MyFileIOException as exc: # handle except MySocketIOException as exc: # handle
有没有更优雅的解决方案?
Some IO operations produce some set of errors. It is important, that it is not one exception, but set. So, we have set for socket errors, set for file io. How to handle group of exceptions without intersection for different io operations?
For example,
OSError
handles file io errors and some(?) Socket errors.I have only one solution: wrap io operations with try-except and raise user-defined exception.
def foo(): try: # some file io except: raise MyFileIOException(reason=sys.exc_info()) try: # some socket io except: raise MySocketIOException(reason=sys.exc_info()) def bar(): try: foo() except MyFileIOException as exc: # handle except MySocketIOException as exc: # handle
Is there some better and elegant solution?
原文:https://stackoverflow.com/questions/33689252
最满意答案
如果要跳过证书验证(不安全),请将verify设置为False。
jira = JIRA('https://some_url/jira', verify=False, basic_auth=('user','password'))
正如@frlan指出的那样,最好验证证书。 只需浏览JIRA参数,并指定您的客户端证书进行验证。
说明: https : //github.com/pycontribs/jira/blob/5cade37e56612caee36db6310b6e0ef935726944/jira/client.py
* verify -- Verify SSL certs. Defaults to ``True``.
If you want to skip the certificate validation(not secure), set verify to False.
jira = JIRA('https://some_url/jira', verify=False, basic_auth=('user','password'))
As @frlan pointed out, it's better to validate the certificate. Just go through the JIRA arguments, and specify your client certificate for validation.
Explanation: https://github.com/pycontribs/jira/blob/5cade37e56612caee36db6310b6e0ef935726944/jira/client.py
* verify -- Verify SSL certs. Defaults to ``True``.
相关问答
更多-
根据JIRA REST API Docs,有一个maxResults URL参数: 的maxResults INT 要返回的最大问题数(默认为50)。 最大允许值由JIRA属性'jira.search.views.default.max'决定。 如果指定的值高于此数字,则搜索结果将被截断。 According to JIRA REST API Docs there's a maxResults URL parameter: maxResults int the maximum number of issue ...
-
使用JIRA REST Client api访问JIRA Agile sprint(Access JIRA Agile sprints with JIRA REST Client api)[2022-02-21]
您想要的所有信息都可以在这里找到: https://docs.atlassian.com/jira/REST/latest/ 请注意,您可以通过以下方式获取项目信息: https : //docs.atlassian.com/jira/REST/latest/#api/2/project a)至于sprint信息 - 你能用JQL获得所需的信息吗? 示例 - 您可以转到问题>搜索问题并使用基本搜索吗? 在这里,在“更多”选项下,您将看到可以指定要过滤的Sprint。 在添加/删除sprint时,您将看到UR ... -
简短回答:1。)不能对结果集进行分组2.)否则无法通过Rest获取小工具数据 Short answer: 1.) no it is not possible to group the result set 2.) no it is not possible to get gadget data over Rest
-
Jira POST&PUT Rest Calls从Python返回错误400(Jira POST & PUT Rest Calls return Error 400 from Python)[2022-06-06]
当请求主体格式错误时,Jira会返回类似“无法实例化类型值...”的错误。 在你的情况下,你提供了一个字符串,Jira需要更复杂的内容(通常是字典)。 It turned out that it was my use of json.dumps(body) in combination with put(..., json=body, ...) causing the issue. Using the json keyword tells Requests to serialize the string a ... -
在我使用过的最有趣的API之一进行了大量研究和卷曲之后,我在这里找到了一些关于Atlassian知识库的非常有用的信息。 该文本的目标是多选自定义字段,但也适用于其他类型的自定义字段。 它清楚地提到JIRA的REST API不提供简单检索多选项自定义字段可用的所有选项的方法 。 因此,这里使用的方法被认为是一种解决方法。 所以我们可以使用 创建问题meta api( 这里 ) 或者编辑问题meta api( 这里 ) 在两个元api链接之后,来自create meta api的参数很简单,但是在编辑元api ...
-
你确定你使用的是正确的转换ID吗? 你有没有检查过 ... / JIRA / REST / API /最新/问题/的Myproj-524 /转换?扩大= transition.fields 您的ID应与您要转换为的转化相匹配。 在我的情况下(使用Jira云附带的标准转换,我的ID是31(对于“完成”) 您可能还需要确认您的工作流程允许从“打开”到“已关闭”处理问题。 您可以从管理>问题>工作流程>分配方案>视图作为图表查看此图表 这里还有一些建议: https://answers.atlassian.com ...
-
如何使用python3访问JIRA-REST API修复证书问题?(How to fix certificate issues with python3 accessing JIRA-REST API?)[2022-03-28]
如果要跳过证书验证(不安全),请将verify设置为False。 jira = JIRA('https://some_url/jira', verify=False, basic_auth=('user','password')) 正如@frlan指出的那样,最好验证证书。 只需浏览JIRA参数,并指定您的客户端证书进行验证。 说明: https : //github.com/pycontribs/jira/blob/5cade37e56612caee36db6310b6e0ef935726944/jir ... -
搜索了很长一段时间后,我找到了解决方案,我在这里发帖给其他有兴趣制作Git / Gerrit钩子的人来做像我这样的事情: 首先在浏览器中打开http://example.com/rest/api/2/issue/
/transitions?expand=transitions.fields ,查找您的网站和发行号以查找转换ID。 假设它是1000: import urllib import urllib2 import base64 import json key = 'JIRA-123' c ... -
不要编码用户名和密码 - 卷曲已经处理了这个! curl -u "username:password" -X GET -H "Content-Type: application/json" https://jira.acme.com/rest/api/2/issue/KEY-666 如果您需要指定基本身份验证,请执行以下操作: curl -D- -X GET -H "Authorization: Basic usernamesndpasswordbase64 -H "Content-Type: appli ...
-
JIRA的REST API目前似乎不支持任何与其search API分开的基于project的查询。 您可以使用JQL在搜索中指定特定项目。 鉴于您了解项目(例如,“JRA-9”中的“JRA”),您可以快速搜索其所有问题: 工作结果: https://jira.atlassian.com/rest/api/latest/search?jql=project=JRA : https://jira.atlassian.com/rest/api/latest/search?jql=project=JRA 一个重要 ...