Trying to grab an xml file from an internet source and parse it for some values.
My code:
def get_xml(self):
#xml_url = "http://www.shoppingcar.it/feed/export_vel.asp?parametro=1"
xml_url = "http://dl.dropbox.com/u/102727/AutoVeloce%20XML%20Splitter/shoppingcar.xml"
MAX_RETRY = 3
retry_left = MAX_RETRY
while retry_left:
try:
req = urlfetch.fetch(xml_url, deadline=10)
XML = req.content.decode('windows-1252')
break # <- done! got file.
except (urllib2.HTTPError, DownloadError):
retry_left -= 1
logging.error("Error while downloading ShoppingCar.xml, retrying.")
except DeadlineExceededError:
retry_left -= 1
logging.warning("DeadlineExceededError while downloading ShoppingCar.xml, retrying.")
except Timeout:
retry_left -= 1
logging.warning("Timeout while downloading ShoppingCar.xml, retrying.")
if retry_left and retry_left < MAX_RETRY:
logging.info("Downloading ShoppingCar.xml succeeded after %s retries.", MAX_RETRY - retry_left)
if not retry_left:
logging.error("Downloading ShoppingCar.xml failed after %s retries.", MAX_RETRY)
return ET.parse(XML)
def _iter_carDicts_in_xml(self, newOnly=True):
#fails here >
tree = self.get_xml()
for veicolo in tree.getiterator('veicolo'):
# do stuff
Error message I get:
<type 'exceptions.IOError'>: [Errno 13] Permission denied: u'<?xml version="1.0" encoding="windows-1252"?><veicoli>\r\n <veicolo>\r\n\t\t<id><![CDATA[26806]]></id>
This error continues spitting out the xml file so i won’t paste it all
Really not sure where to go on this one, I’ve used similar code to extract from xml files and never had this kind of problem. Any ideas?
parsefunction expects file object. Tryparse(StringIO(XML))instead.