3

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))
wowkin2
  • 5,895
  • 5
  • 23
  • 66
mongotop
  • 7,114
  • 14
  • 51
  • 76
  • 1
    I feel there are couple of missing information in here, one being `What code are you using to scrape the xml ?` and second is, `Do you want to rollback the xml read operation or any other API ?` – Nagaraj Tantri Jun 18 '18 at 12:31
  • I added more info to the code in the question. that is where I get None value as return every now and then. but since I have `try/except` statement the code keep running. – mongotop Jun 18 '18 at 18:35
  • Do you get error in here: `response_xml_data_next = ET.ElementTree(ET.fromstring(response_str_data_next))` and you want to rollback from where? Are you running this in a for loop to rollback ? – Nagaraj Tantri Jun 20 '18 at 07:13
  • yes. I get error because `request_data_next == None` and yes. I use that is a `while loop` while there's more remain data from the resultId cursor. – mongotop Jun 20 '18 at 17:08
  • 1
    Since i don't have the exact reproducing scenario, so more questions: 1. When you say `request_data_next == None` does that mean the request before opening is failing? 2. When you say rollback do you want to re try that API or neglect that specific `result_id` ? – Nagaraj Tantri Jun 21 '18 at 12:06
  • 1 - yes. 2 - re-try the api and keep the cursor in the location where the error occurred because when it error happens the cursor move to the new set and pull it and ignore the once where the error occurred. – mongotop Jun 25 '18 at 22:13
  • Can you provide that part of XML where parser is complaining? Near 57565 symbols. – wowkin2 Jun 02 '21 at 13:43

1 Answers1

0

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.

wowkin2
  • 5,895
  • 5
  • 23
  • 66