gpt4 book ai didi

python - 在 python 中处理 SOAP 类型异常的最佳方法是什么

转载 作者:太空宇宙 更新时间:2023-11-04 06:26:42 24 4
gpt4 key购买 nike

如果用户输入的数据不在 WSDL 访问的 Web 服务器上,我会得到一个错误:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://soap.rpc.jira.atlassian.com" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns2:Body>
<ns1:getFieldsForEdit>
<in0 xsi:type="ns3:string">FmofSimScl</in0>
<in1 xsi:type="ns3:string">QA-65000</in1>
</ns1:getFieldsForEdit>
</ns2:Body>
</SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://soap.rpc.jira.atlassian.com" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns2:Body>
<ns1:getIssue>
<in0 xsi:type="ns3:string">FmofSimScl</in0>
<in1 xsi:type="ns3:string">QA-65000</in1>
</ns1:getIssue>
</ns2:Body>
</SOAP-ENV:Envelope>
Traceback (most recent call last):
File "/home/qa/jira-test/.hg/check_jira.py", line 64, in <module>
main()
File "/home/qa/jira-test/.hg/check_jira.py", line 12, in main
commit_text_verified = verify_commit_text(os.popen('hg tip --template "{desc}"'))
File "/home/qa/jira-test/.hg/check_jira.py", line 35, in verify_commit_text
if CheckForJiraIssueRecord(m_args) == 0:
File "/home/qa/jira-test/.hg/check_jira.py", line 58, in CheckForJiraIssueRecord
issue = com.run(command_name, logger, jira_env, my_args)
File "/home/qa/jira-test/.hg/jira.py", line 1367, in run
return self.commands[command].dispatch(logger, jira_env, args)
File "/home/qa/jira-test/.hg/jira.py", line 75, in dispatch
results = self.run(logger, jira_env, args)
File "/home/qa/jira-test/.hg/jira.py", line 174, in run
logger.error(decode(e))
File "/home/qa/jira-test/.hg/jira.py", line 1434, in decode
str = e.faultstring
AttributeError: 'WebFault' object has no attribute 'faultstring'
transaction abort!
rollback completed
abort: pretxncommit.jira hook exited with status 1

有没有办法处理这个问题,这样我就可以编写自己的错误字符串或警告消息来代替所有这些。如果我关闭标准输出,我不会得到 xml 数据,但我仍然会得到:

transaction abort!rollback completedabort: pretxncommit.jira hook exited with status 1

which is from mercurial, but would be nice to have a an error string appended to it likewarnings.warn("%s does not exist"%issue_id)

ok, i looked in jira.pyand changed on line 1434 :str = e.faultstringtostr = e.fault

and got:

faultcode = "soapenv:Server.userException"
faultstring = "com.atlassian.jira.rpc.exception.RemotePermissionException: This issue does not exist or you don't have permission to view it."
detail =
(detail){
com.atlassian.jira.rpc.exception.RemotePermissionException = ""
hostname = "JIRA"
}
}

最佳答案

它已在 jira.py 中修复:将解码函数更改为:


def decode(e):
"""Process an exception for useful feedback"""
# TODO how to log the fact it is an error, but allow info to be unchanged?
# TODO now fault not faultstring?
# The faultType class has faultcode, faultstring and detail
str = e.fault
if str == 'com.atlassian.jira.rpc.exception.RemotePermissionException':
return "This issue does not exist or you don't have permission to view it"
return e.fault

代替:


def decode(e):
"""Process an exception for useful feedback"""
# TODO how to log the fact it is an error, but allow info to be unchanged?
# TODO now fault not faultstring?
# The faultType class has faultcode, faultstring and detail
str = e.faultstring
if str == 'java.lang.NullPointerException':
return "Invalid issue key?"
return e.faultstring

关于python - 在 python 中处理 SOAP 类型异常的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7529703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com