API仅占我列表的一半

时间:2017-09-23 21:17:34

标签: python api dictionary

正如本回答A Python dictionary with repeated fields所示,我试图通过python和zeep模块向API发送一个dicts列表。

但是,API只收到我的一半数据。

API需要一个dict并接受参数dataArray,如下所示:

<dataArray>
  <AccountingYearData>
    <Handle>
      <Year>string</Year>
    </Handle>
    <Year>string</Year>
    <FromDate>dateTime</FromDate>
    <ToDate>dateTime</ToDate>
    <IsClosed>boolean</IsClosed>
  </AccountingYearData>
  <AccountingYearData>
    <Handle>
      <Year>string</Year>
    </Handle>
    <Year>string</Year>
    <FromDate>dateTime</FromDate>
    <ToDate>dateTime</ToDate>
    <IsClosed>boolean</IsClosed>
  </AccountingYearData>
</dataArray>

查看完整字符串https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?op=AccountingYear_CreateFromDataArray

的此链接

所以我喜欢这个:

data = [
    {
        'AccountingYearData':{
            'Handle':{'Year':'2018'}, 
            'Year':'2018',
            'FromDate':'2018-01-01', 
            'ToDate':'2018-12-31', 
            'IsClosed':'False'
            },
        },
    {
        'AccountingYearData':{
            'Handle':{'Year':'2019'}, 
            'Year':'2019',
            'FromDate':'2019-01-01', 
            'ToDate':'2019-12-31', 
            'IsClosed':'False'
            },
        },
    ]

c.service.AccountingYear_CreateFromDataArray(dataArray = data)

但有了这个,API只能获得一半的数据。

将列表插入如下的字典:

data = {
    'dataArray': {
        [
            {...},
            {...}
        ]
    }
}

c.service.AccountingYear_CreateFromDataArray(data)

API不接受。

有没有办法解决这个问题?

最诚挚的问候 Kresten

编辑:

我的完整代码是:

from zeep import Client
import datetime

AppSecretToken = 'xxxx'
AgreementGrantToken = 'xxxx'

c = Client("https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL")
c.service.ConnectWithToken(token=AgreementGrantToken, appToken=AppSecretToken)

data = [\
    {'AccountingYearData': {\
        'Handle': {'Year': '2018'},\
        'Year': '2018',\
        'FromDate': datetime.date(2018,1,1),\
        'ToDate': datetime.date(2018,12,31), \
        'IsClosed': False }\
    }, \
    {'AccountingYearData': {\
        'Handle': {'Year': '2019'},\
        'Year': '2019',\
        'FromDate': datetime.date(2019,1,1),\
        'ToDate': datetime.date(2019,12,31), \
        'IsClosed': False }\
    } \
]\

print(c.service.AccountingYear_CreateFromDataArray(dataArray = data))

data = {'dataArray': \
[\
    {'AccountingYearData': {\
        'Handle': {'Year': '2018'},\
        'Year': '2018',\
        'FromDate': datetime.date(2018,1,1),\
        'ToDate': datetime.date(2018,12,31), \
        'IsClosed': False }\
    }, \
    {'AccountingYearData': {\
        'Handle': {'Year': '2019'},\
        'Year': '2019',\
        'FromDate': datetime.date(2019,1,1),\
        'ToDate': datetime.date(2019,12,31), \
        'IsClosed': False }\
    } \
]\
}

print(c.service.AccountingYear_CreateFromDataArray(data))

响应:

[{
    'Year': '2018'
}]
None

0 个答案:

没有答案