Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python XML错误_Python_Xml_Django - Fatal编程技术网

Python XML错误

Python XML错误,python,xml,django,Python,Xml,Django,我有以下Python代码,在Django中运行 from django.http import HttpResponse from django.shortcuts import render from django.template import RequestContext, loader from pptx import Presentation import uuid from lxml import etree, objectify from xml.sax.saxutils impo

我有以下Python代码,在Django中运行

from django.http import HttpResponse
from django.shortcuts import render
from django.template import RequestContext, loader
from pptx import Presentation
import uuid
from lxml import etree, objectify
from xml.sax.saxutils import escape

def make(request):
        information = '''<rss version="0.92"><channel><title>JIRA</title><description>An XML representation of a search request</description><language>en-us</language><issue start="0" end="6" total="6"/><build-info><version>6.1-OD-09-WN</version><build-number>6144</build-number><build-date>15-09-2013</build-date></build-info><item><summary>Purchase order submitted to Dell</summary><component>Summer Scaling</component></item></channel></rss>'''
        tree = objectify.fromstring(information)

        components = {}

        for item in tree.channel.item:
                component = str(item.component)
                summary = str(item.summary).strip()
                if component not in components:
                        components[component] = []
                components[component].append(summary)

        prs = Presentation()

        slidelayout = prs.slidelayouts[1]
        for component, summaries in components.iteritems():
                slide = prs.slides.add_slide(slidelayout)
                title = slide.shapes.title
                title.text = str(component)
                body = slide.shapes.placeholders[1]
                first = True
                for summary in summaries:
                        if first:
                                body.textframe.text = summary
                                first = False
                        else:   
                                body.textframe.add_paragraph().text = summary

        filename = '/home/ubuntu/src/jiraxmlapp/download/' + str(uuid.uuid1()) + 'update.pptx'
        prs.save(filename)

        f = open(filename, 'r')
        ppt_content = f.read()

        response = HttpResponse(ppt_content, content_type="application/vnd.openxmlformats-officedocument.presentationml.slideshow")
        response['Content-Disposition'] = 'attachment; filename="status.pptx"'
        return response;
我在w3school的网站上测试了XML的语法,它说没有语法错误。我尝试过以不同的方式格式化XML字符串。。。全部在一条线上,分布在多条线上,等等。同样的错误会继续出现

为了让事情更加混乱,当我从shell解释器运行前两行(information=..和tree=..)时,一切都正常


我准备把头发拔出来。任何帮助都将不胜感激。

w3schools很快就会忘记,因为他们的大多数例子都是假的。要检查您的xml,您可以使用
xmllint
或官方的xml验证器,这里是您的提要,现在是关于您的提要的,看起来JIRA正在通过添加意外节点来破坏提要。我所说的“意外”是指RSS提要不允许使用这些节点。胡乱猜测:可能您需要在
信息的开头使用
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/ubuntu/src/jiraxmlapp/pptmaker/views.py" in make
  17.   tree = objectify.fromstring(information)

Exception Type: XMLSyntaxError at /pptmaker/pptmaker/make/
Exception Value: None