rollback to the previous offset when an error is throw while pulling data from Intacct

212 views Asked by At

When my script is pulling the data from Intacct 100 xml object at a time everything is working fine using my resultid to remember the offset and pull the next once, and for some reason, it gets to one of the loops and it throws an error saying not well-formed (invalid token): line 1, column 57565 knowing I'm using the same credentials all the time. With that error thrown it skips a 100 object and move to the next one and keep pulling the data.

My question is: how to rollback after I get an error so my resultid won't skip the data when the error is thrown? is there's a function or something I should add to my XML query?

Please see below for my current XML query.

Thank you!

headers     = {'Content-type': 'x-intacct-xml-request'}   
API_URL     = 'https://api.intacct.com/ia/xml/xmlgw.phtml'
req_shell_next="""<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE request SYSTEM "intacct_request.v2.1.dtd">
    <request>
      <control>
        <senderid>%s</senderid>
        <password>%s</password>
        <controlid>testRequestId</controlid>
        <uniqueid>false</uniqueid>
        <dtdversion>3.0</dtdversion>
        <includewhitespace>false</includewhitespace>
      </control>
      <operation>
        <authentication>
          <login>
            <userid>%s</userid>
            <companyid>%s</companyid>
            <password>%s</password>
          </login>
        </authentication>
        <content>
          <function controlid="PostJSONObjectCID">
            <readMore>
               <resultId>%s</resultId>
            </readMore>
          </function>
        </content>
      </operation>
    </request>"""

request_data_next               = urllib2.Request(API_URL, req_shell_next % (auth_info_senderid, auth_info_password, auth_info_userid, auth_info_companyid, auth_info_userpw, resultId ), headers)
response_str_data_next          = urllib2.urlopen(request_data_next).read()
response_xml_data_next          = ET.ElementTree(ET.fromstring(response_str_data_next))
1

There are 1 answers

0
wowkin2 On

There is no way to move cursor back in readMore queries (documenation).

Your problem is not on Intacct side, but on app code: during parsing response using lxml or any other XML parser. So you need to do error handling (at least try/except) and/or retries there.

Please save raw responses from Intacct, so you'll be able to investigate or debug parsing issues.