首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 ><type 'exceptions.IOError'>:[Errno 13]拒绝在appengine上使用cElementTree的权限

<type 'exceptions.IOError'>:[Errno 13]拒绝在appengine上使用cElementTree的权限
EN

Stack Overflow用户
提问于 2011-09-04 20:53:01
回答 2查看 1.5K关注 0票数 0

尝试从internet源抓取xml文件,并对其进行解析以获得一些值。我的代码:

代码语言:javascript
运行
复制
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

我收到的错误消息:

代码语言:javascript
运行
复制
<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文件中提取,从来没有遇到过这种问题。有什么想法吗?

EN

Stack Overflow用户

回答已采纳

发布于 2011-09-04 22:25:12

parse函数需要文件对象。请尝试使用parse(StringIO(XML))

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7299344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档