我正在尝试使用Soap API将一些文件附加到Jira。 我有python 2.6和SOAPpy不再工作了,所以,我正在使用suds。一切都很好,除了附件...我不知道如何重写这段代码:http://confluence.atlassian.com/display/JIRA/Creating+a+SOAP+Client?focusedCommentId=180943#comment-180943
有任何线索吗? 我不知道如何处理像这样的复杂类型:
<complexType name="ArrayOf_xsd_base64Binary">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:byte[][]"/>
</restriction>
</complexContent>
</complexType>
非常感谢
<磷>氮答案 0 :(得分:1)
如果您不想使用Java CLI,下面是如何在Python中添加和附件。
from suds.client import Client
client = Client(url_to_wsdl_file)
auth = client.service.login(username, password)
client.service.addBase64EncodedAttachmentsToIssue(auth, issue_key, [filename.encode("utf-8")], [open(full_path_and_filename, "rb").read().encode('base64')])
答案 1 :(得分:0)
dunno如果这有帮助,但是当我使用python时,手柄wsdls我发现大多数软件包中的复杂类型都缺乏支持。最后,我决定使用wsdl2py --complexType wsdl_url在zsi上。这非常有效。我的wsdl中有许多复杂类型,wsdl中定义了数组数组。 wsdl2py生成3个访问wsdl时使用的库。下面是一个调用方法createSubscribers的示例,该方法接受值数组。
import inspect, sys
from PolicyManagementService_client import *
class apiCheckSetup:
def __init__(self, host="10.10.10.23", port="8080", log=None):
"""Setup to run wsdl operations"""
self.loc=PolicyManagementServiceLocator(host, port)
if log:
logfile=log
else:
logfile=sys.stdout
kw = { 'tracefile' : logfile}
self.port=self.loc.getPolicyManagementPort(**kw)
def createSubscribers(self, subList):
req=createSubscribers()
subscriberList=ns0.subscriberDetailsList_Def("subscriberList")
subscriber=ns0.subscriberDetails_Def("subscriber")
subUsers=subscriberList.pyclass()
for element in subList:
sub=subscriber.pyclass()
sub.set_attribute_msisdn(element['msisdn'])
sub.set_attribute_policyID(element['policyID'])
sub.set_attribute_firstName(element['firstName'])
sub.set_attribute_lastName(element['lastName'])
subUsers._subscriber.append(sub)
req._subscribers=subUsers
self.port.createSubscribers(req)
这可以像这样调用:
subList=[{'msisdn' : '+445555555', 'policyID' : pid, 'firstName' : 'M1', 'lastName' : 'D1'}, {'msisdn' : '+445555556', 'policyID' : pid, 'firstName' : 'M2', 'lastName' : 'D2'}]
self.api=pmcApiMethods.apiCheckSetup(host=testConfig.pmcApiServer, port=testConfig.pmcApiPort)
self.api.createSubscribers(subList)
Dunno,如果有任何帮助
答案 2 :(得分:0)
您可以使用Jira CLI(使用suds编写的Python语言)将文件附加到问题。 The standalone code在LGPL许可下可用。
您将使用的命令是“attach”。
我在python 2.7下使用此CLI附加文件时出错:
Traceback (most recent call last):
File "./jira", line 1281, in <module>
rc = com.run(command_name, logger, jira_env, args[1:])
File "./jira", line 1080, in run
return self.commands[command].dispatch(logger, jira_env, args)
File "./jira", line 70, in dispatch
results = self.run(logger, jira_env, args)
File "./jira", line 140, in run
logger.error(decode(e))
File "./jira", line 1142, in decode
str = e.faultstring
AttributeError: 'exceptions.NameError' object has no attribute 'faultstring'
我只是致电Java CLI并且它有效!
# Run JAVA CLI attach script
args = [
'./jira.sh',
'--action',
'addAttachment',
'--project',
project_title,
'--issue',
issue_key,
'--file',
'%s/%s' % (path, filename),
]
output = subprocess.check_output(args, cwd = path_to_java_cli).decode("utf-8")