首页 \ 问答 \ 分别处理特定(for io)异常(Handle specific (for io) exception separately)

分别处理特定(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
更新时间:2023-12-18 21:12

最满意答案

如果要跳过证书验证(不安全),请将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 ...
  • 您想要的所有信息都可以在这里找到: 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会返回类似“无法实例化类型值...”的错误。 在你的情况下,你提供了一个字符串,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 ...
  • 如果要跳过证书验证(不安全),请将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 一个重要 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)