0

I have xml which is having 6042 lines of data.

I am parsing it by following code ,

import urllib2
import lxml.etree as ET
print 'Started Execution here'
url="url goes here"
xmldata = urllib2.urlopen(url).read()
root = ET.fromstring(xmldata)
print 'Done'
print root
for xin in root:
    print xin.tag, xin.attrib

Sometimes it runs successfully , but sometimes it shows following errors,

1. lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: ClinicID line 54 and location, line 54, column 60016

2. httplib.IncompleteRead: IncompleteRead(964 bytes read)

Clarification for 1st error : I have downloaded XmlValidator and just copied my xml to this application. And it show no errors in it. It clearly shows that xml is totally error free.

Then whats wrong i am doing here ?

Any help will be appreciated.

Here is my xml format

<locations>
    <location>
        <LocationID>A</LocationID>
        <ClinicID>111</ClinicID>
        <buildingType>A Type</buildingType>
        <address>Address</address>
        <address2>>Address 1</address2>
        <city>City 1</city>
        <state>State 1</state>
        <zip>Zip 1</zip>
    </location>
    <location>
        <LocationID>A</LocationID>
        <ClinicID>111</ClinicID>
        <buildingType>A Type</buildingType>
        <address>>Address</address>
        <address2>>Address</address2>
        <city>City 1</city>
        <state>State 1</state>
        <zip>Zip 1</zip>
    </location>
    .   
    .
    .
    .
    .
    .
    <location>
        <LocationID>A</LocationID>
        <ClinicID>111</ClinicID>
        <buildingType>A Type</buildingType>
        <address>>Address</address>
        <address2>>Address</address2>
        <city>City 1</city>
        <state>State 1</state>
        <zip>Zip 1</zip>
    </location>


</locations>

UPDATE

I have downloaded xml file and tried to open it locally . It is working without any error. Then why sometime it is not working with urllib2.urlopen(url).read() ? Any limitations ?

Nishant Nawarkhede
  • 8,234
  • 12
  • 59
  • 81

0 Answers0