<type 'exceptions.IOError'>: [Errno 13] 权限被拒绝,使用cElementTree在appengine上
我正在尝试从网上获取一个xml文件,并从中提取一些值。我的代码是:
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
我收到的错误信息是:
<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>
这个错误一直在输出xml文件,所以我就不把它全部贴出来了。
我真的不知道该怎么解决这个问题,我之前用类似的代码提取xml文件时从来没有遇到过这种问题。有什么建议吗?
2 个回答
-1
你可能没有权限使用这个链接(也就是说,你不能通过这个链接发起请求)。
1
parse
函数需要一个文件对象。你可以试试用 parse(StringIO(XML))
这样的方式。