开发者

Python+suds : xsd_base64Binary type?

I'm trying to attach some files to a Jira using the Soap API. I have python 2.6 and SOAPpy isn't working any more, so, I'm using suds. Everything is fine except for the attachements ... I don't know how to rewrite this piece of code : http://confluence.atlassian.com/display/JIRA/Creating+a+SOAP+Client?focusedCommentId=180943#comment-180943

Any clue ? I don't know how to deal with complex type like this one :

<complexType name="ArrayOf_xsd开发者_运维知识库_base64Binary">

<complexContent>

<restriction base="soapenc:Array">

<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:byte[][]"/>

</restriction>

</complexContent>

</complexType>

thanks a lot

n.


If you do not want to use the Java CLI, below is how to add and attachment in 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')])


dunno if this helps but when I was using python the handle wsdls I found a distinct lack of support in most packages for complex types. In the end I decided on zsi with its wsdl2py --complexType wsdl_url. This worked perfectly. I had many complex types in my wsdl with arrays of arrays of arrays defined in the wsdl. wsdl2py generates 3 libs that you use when accessing the wsdl. Here is an example of a call to a method createSubscribers which takes in arrays of values.

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)

This can be called like so:

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 if this is any help


You can attach a file to an issue using the Jira CLI (written in Python using suds). The standalone code is available under an LGPL license.

The command you would use is "attach".

Update: Python CLI not working.

I am having errors attaching files with this CLI under python 2.7:

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'

Update 2: Java CLI working.

I just call the Java CLI and it works!

# 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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜