在打印属性时,代码无法识别SOAP响应中的属性

时间:2016-07-15 14:26:09

标签: python-2.7 pandas soap dataframe exacttarget

我正在使用ExactTarget FUEL SDK从SalesForce Marketing Cloud中检索数据。更具体地说,我致力于调用“Unsub Events”(https://github.com/salesforce-marketingcloud/FuelSDK-Python/blob/master/objsamples/sample_unsubevent.py#L15),但SOAP响应的结构有几个更深层次的嵌套字典对象,我需要迭代并放入数据帧。这是响应的样子,我需要将每个变量放在单独的数据帧中。

(UnsubEvent){
   Client = 
      (ClientID){
         ID = 11111111
      }
   PartnerKey = None
   CreatedDate = 2016-07-13 13:37:46.000663
   ModifiedDate = 2016-07-13 13:37:46.000663
   ID = 11111111
   ObjectID = "11111111"
   SendID = 11111111
   SubscriberKey = "aaa@aaa.com"
   EventDate = 2016-07-13 13:37:46.000663
   EventType = "Unsubscribe"
   TriggeredSendDefinitionObjectID = None
   BatchID = 1
   List = 
      (List){
         PartnerKey = None
         ID = 11111111
         ObjectID = None
         Type = "aaaa"
         ListClassification = "aaa"
      }
   IsMasterUnsubscribed = False
 }]

我已成功将所有变量放在数据框中,除了一个“ListClassification”。 我收到错误“列表实例没有属性'ListClassification',我的问题是,如果我能在响应中看到该属性,为什么会发生这种情况?并且该问题有解决方法吗?

我的代码:

import ET_Client
import pandas as pd



try:
    debug = False
    stubObj = ET_Client.ET_Client(False, debug)

    print '>>>UnsubEvents'
    getUnsubEvent = ET_Client.ET_UnsubEvent()
    getUnsubEvent.auth_stub = stubObj
    getResponse3 = getUnsubEvent.get()
    ResponseResultsUnsubEvent = getResponse3.results
    #print ResponseResultsUnsubEvent

    ClientIDUnsubEvents = []
    partner_keys3 = []
    created_dates3 = []
    modified_date3 = []
    ID3 = []
    ObjectID3 = []
    SendID3 = []
    SubscriberKey3 = []
    EventDate3 = []
    EventType3 = []
    TriggeredSendDefinitionObjectID3 = []
    BatchID3 = []
    IsMasterUnsubscribed = []
    ListPartnerKey = [] 
    ListID = []
    ListObjectID = []
    ListType = []
    ListClassification = []


    for UnsubEvent in ResponseResultsUnsubEvent:
        ClientIDUnsubEvents.append(str(UnsubEvent['Client']['ID']))
        partner_keys3.append(UnsubEvent['PartnerKey'])
        created_dates3.append(UnsubEvent['CreatedDate'])
        modified_date3.append(UnsubEvent['ModifiedDate'])
        ID3.append(UnsubEvent['ID'])
        ObjectID3.append(UnsubEvent['ObjectID'])
        SendID3.append(UnsubEvent['SendID'])
        SubscriberKey3.append(UnsubEvent['SubscriberKey'])
        EventDate3.append(UnsubEvent['EventDate'])
        EventType3.append(UnsubEvent['EventType'])
        TriggeredSendDefinitionObjectID3.append(UnsubEvent['TriggeredSendDefinitionObjectID'])
        BatchID3.append(UnsubEvent['BatchID'])
        IsMasterUnsubscribed.append(UnsubEvent['IsMasterUnsubscribed'])

        ListPartnerKey.append(str(UnsubEvent['List']['PartnerKey']))
        ListID.append(str(UnsubEvent['List']['ID']))
        ListObjectID.append(str(UnsubEvent['List']['ObjectID']))
        ListType.append(str(UnsubEvent['List']['Type']))
        ListClassification.append(str(UnsubEvent['List']['ListClassification']))

    df3 = pd.DataFrame({'ListPartnerKey':ListPartnerKey,'ListID':ListID,'ListObjectID':ListObjectID,'ListType':ListType,
                        'ClientID':ClientIDUnsubEvents,'PartnerKey':partner_keys3,'CreatedDate':created_dates3,
                        'ModifiedDate':modified_date3,'ID':ID3,'ObjectID':ObjectID3,'SendID':SendID3,'SubscriberKey':SubscriberKey3,
                        'EventDate':EventDate3,'EventType':EventType3,'TriggeredSendDefinitionObjectID':TriggeredSendDefinitionObjectID3,
                        'BatchID':BatchID3,'ListClassification':ListClassification,'IsMasterUnsubscribed':IsMasterUnsubscribed})

    print df3

字面上所有其他属性都会进入数据框,但不确定为什么“ListClassification”没有被选中。

提前感谢您的帮助!

0 个答案:

没有答案