从中提取数据时引发错误时回滚到上一个偏移量

2024-10-04 07:37:07 发布

您现在位置:Python中文网/ 问答频道 /正文

当我的脚本一次从Intacct 100 xml object中提取数据时,使用resultid记住偏移量并拉下一次,由于某种原因,它到达一个循环并抛出一个错误,说not well-formed (invalid token): line 1, column 57565知道我一直在使用相同的凭据。抛出这个错误后,它将跳过一个100个对象,并移动到下一个对象并继续提取数据。在

我的问题是:如何在收到错误后回滚,以便在抛出错误时resultid不会跳过数据?有没有什么我应该添加到我的xml查询中的函数或东西?在

请参阅下面我当前的xml查询。在

谢谢你!在

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))

Tags: 数据infoauthdatarequest错误passwordxml