Python Zeep AttributeError: 'NoneType' object has no attribute 'elements' [switching to suds-community]

Python Zeep AttributeError: 'NoneType' object has no attribute 'elements' [switching to suds-community]

这是一个由两部分组成的问题,针对以下代码:

from zeep import Client
from datetime import datetime
import logging.config

logging.config.dictConfig({
    "version": 1,
    "formatters": {"verbose": {"format": "%(asctime)s # [%(name)s]: %(message)s"}},
    "handlers": {"console": {"level": "DEBUG", "class": "logging.StreamHandler", "formatter": "verbose"}},
    "loggers": {"zeep.transports": {"level": "DEBUG", "propagate": True, "handlers": ["console"]}}
})

client = Client("https://t-mobile.provisioning.blackberry.com/webservices/Provisioning?wsdl")

client.service._binding_options['address'] = "https://t-mobile.provisioning.blackberry.com/webservices/Provisioning"

ProvisionRequest = {
    "provisionRequest": {
        "body": [{
            "ProvisionReqEntity" : {            
                "items": [{
                    "ProvisionDataItem": {
                        "name": "MSISDN",   
                        "data": "123456789"
                    }
                }],
                "name": "subscriber"
            }
        }],
        "header": {
            "sender": {
                "id": "123",
                "loginId": "myLoginId",
                "name": "myName",
                "password": "myPassword"
            },
            "timeFormat": "CCYY-MM-DDThh:mm:ssZ",
            "timeStamp": datetime.now().astimezone().replace(microsecond=0).isoformat()
        },
        "productType": "BlackBerry",
        "transactionId": "123123123123",
        "transactionType": "Status",
        "version": "1.2"
    }
}

response = client.service.echoTest( **ProvisionRequest )
print(response)

1) 我似乎无法使请求正文与 ProvisionReqEntity 所需的数组结构相匹配。所需请求应如下所示:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prov="http://www.blackberry.com/webservices/Provisioning" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <prov:echoTest soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <provisionRequest xsi:type="java:ProvisionRequest" xmlns:java="java:provision.control.ari.comm.soap">
            <body xsi:type="java:ArrayOfProvisionReqEntity" soapenc:arrayType="java:ProvisionReqEntity[1]">
                <ProvisionReqEntity>
                   <name xsi:type="xsd:string">subscriber</name>
                   <items soapenc:arrayType="java:ProvisionDataItem[1]">
                      <ProvisionDataItem>
                         <name xsi:type="xsd:string">MSISDN</name>
                         <data xsi:type="xsd:string">123456789</data>
                      </ProvisionDataItem>
                   </items>
                </ProvisionReqEntity>
            </body>
            <header xsi:type="java:ProvisionReqHeader">
               <sender xsi:type="java:ProvisionSender">
                  <id xsi:type="xsd:string">123</id>
                  <loginId xsi:type="xsd:string">myLoginId</loginId>
                  <name xsi:type="xsd:string">myName</name>
                  <password xsi:type="xsd:string">myPassword</password>
               </sender>
               <timeFormat xsi:type="xsd:string">CCYY-MM-DDThh:mm:ssZ</timeFormat>
               <timeStamp xsi:type="xsd:string">${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())}</timeStamp>
            </header>
            <productType xsi:type="xsd:string">BlackBerry</productType>
            <transactionId xsi:type="xsd:string">123123123123</transactionId>
            <transactionType xsi:type="xsd:string">Status</transactionType>
            <version xsi:type="xsd:string">1.2</version>
         </provisionRequest>
      </prov:echoTest>
   </soapenv:Body>
</soapenv:Envelope>

但是; Zeep 显示 ProvisionReqEntity 的以下内容:

<ns1:body xmlns:ns1="java:provision.control.ari.comm.soap">
    <ProvisionReqEntity>
        <ns1:items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        <ns1:name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        <ns1:optionalTokens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        <ns1:subEntities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        <ns1:type xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    </ProvisionReqEntity>
</ns1:body>

2) 为什么 Python / Zeep 不打印 response?记录器清楚地显示我收到了有效回复。

奖金问题::-)

3) client.service._binding_options['address'] 是修改端点的推荐方法吗?

我通过切换到 suds-community 解决了我的问题。

from suds.client import Client
from datetime import datetime
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

client = Client('https://t-mobile.provisioning.blackberry.com/webservices/Provisioning?wsdl')

client.set_options(location='https://t-mobile.provisioning.blackberry.com/webservices/Provisioning')

ProvisionRequest = {
    'body': [{
        'items': [{
            'name': "MSISDN",
            'data': "123456789"
        }],
        'name': "subscriber"
    }],
    'header': {
        'sender': {
            'id': "123",
            'loginId': "myLoginId",
            'name': "myName",
            'password': "myPassword"
        },
        'timeFormat': "CCYY-MM-DDThh:mm:ssZ",
        'timeStamp': datetime.now().astimezone().replace(microsecond=0).isoformat()
    },
    'productType': "BlackBerry",
    'transactionId': "123123123123",
    'transactionType': "Status",
    'version': "1.2"
}

response = client.service.echoTest( ProvisionRequest )
print(response)