ExpatError +不匹配的标签+ expatbuilder.py

时间:2012-10-25 14:47:01

标签: django python-2.7 e-commerce

我正在尝试通过Jim McGaw开始Django电子商务。在完成第5章的过程中,在介绍google-checkout选项后,我面临以下错误。谁能给我一些建议/可能的解决方案?

代码段如下,


$ 

    def get_checkout_url(request):
        redirect_url =''
        req = _create_google_checkout_request(request)
        try:
            response_xml = urlopen(req).read()
        except HTTPError, err:
            raise err
        except URLError, err:
            raise err
        else:
            redirect_url = _parse_google_checkout_response(response_xml)
        return redirect_url


    $ def _parse_google_checkout_response(response_xml):
        redirect_url = ""
        print response_xml
        xml_doc = minidom.parseString(response_xml)  # -- Breaks here --
    #   xml_doc = minidom.parse(response_xml)
        root = xml_doc.documentElement
        node = root.childNodes[1]
        if node.tagName == 'redirect-url':
            redirect_url = node.firstChild.data
        if node.tagName == 'error-message':
            raise RuntimeError(node.firstChild.data)
        return redirect_url

错误日志如下:


**Environment:**

Django Version: 1.4.1
Python Version: 2.7.1


Traceback:
File "/Users/username/work/pythonwork/djtrunk/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/username/work/pythonwork/ecomstore/cart/views.py" in show_cart
  19.             checkout_url = checkout.get_checkout_url(request)
File "/Users/username/work/pythonwork/ecomstore/checkout/checkout.py" in get_checkout_url
  6.     return google_checkout.get_checkout_url(request)
File "/Users/username/work/pythonwork/ecomstore/checkout/google_checkout.py" in get_checkout_url
  27.         redirect_url = _parse_google_checkout_response(response_xml)
File "/Users/username/work/pythonwork/ecomstore/checkout/google_checkout.py" in _parse_google_checkout_response
  46.     xml_doc = minidom.parseString(response_xml)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/minidom.py" in parseString
  1924.         return expatbuilder.parseString(string)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py" in parseString
  940.     return builder.parseString(string)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py" in parseString
  223.             parser.Parse(string, True)

Exception Type: ExpatError at /cart/
Exception Value: mismatched tag: line 1460, column 4

0 个答案:

没有答案