Python+suds:xsd_base64Binary 类型?

发布于 2024-08-22 07:06:57 字数 782 浏览 10 评论 0原文

我正在尝试使用 Soap API 将一些文件附加到 Jira。 我有 python 2.6 并且 SOAPpy 不再工作,所以,我正在使用 suds。除了附件之外,一切都很好......我不知道如何重写这段代码: http://confluence.atlassian.com/display/JIRA/Creating+a+SOAP+Client?focusedCommentId=180943#comment-180943

任何线索? 我不知道如何处理这样的复杂类型:







非常感谢

n。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌化 2024-08-29 07:06:57

如果您不想使用 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')])

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')])
ら栖息 2024-08-29 07:06:57

不知道这是否有帮助,但是当我使用 python 句柄 wsdls 时,我发现大多数包明显缺乏对复杂类型的支持。最后我决定使用 zsi 及其 wsdl2py --complexType wsdl_url。这非常有效。我的 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 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

余生一个溪 2024-08-29 07:06:57

您可以使用 Jira CLI(使用 suds 用 Python 编写)将文件附加到问题。 独立代码可用根据 LGPL 许可证。

您将使用的命令是“attach”。

更新:Python CLI 不工作。

我在 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'

更新 2:Java CLI 工作。

我只是调用 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")

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文