我正在尝试通过 Jim McGaw 开始 Django 电子商务。在完成第 5 章时,在引入 google-checkout 选项后,我遇到了以下错误。谁能给我一些建议/可能的解决方案?
代码片段如下,
$
def get_checkout_url(请求):
重定向网址 =''
req = _create_google_checkout_request(请求)
尝试:
response_xml = urlopen(req).read()
除了 HTTPError,错误:
提出错误
除了 URLError,错误:
提出错误
别的:
redirect_url = _parse_google_checkout_response(response_xml)
返回重定向网址
$ def _parse_google_checkout_response(response_xml):
重定向网址 = ""
打印 response_xml
xml_doc = minidom.parseString(response_xml) # -- 在这里打断 --
# xml_doc = minidom.parse(response_xml)
根 = xml_doc.documentElement
节点 = root.childNodes[1]
如果 node.tagName == 'redirect-url':
redirect_url = node.firstChild.data
如果 node.tagName == '错误消息':
引发 RuntimeError(node.firstChild.data)
返回重定向网址
错误日志如下:
**环境:** Django 版本:1.4.1 Python版本:2.7.1 追溯: get_response 中的文件“/Users/username/work/pythonwork/djtrunk/django/core/handlers/base.py” 111. 响应 = 回调(请求,*callback_args,**callback_kwargs) show_cart 中的文件“/Users/username/work/pythonwork/ecomstore/cart/views.py” 19. checkout_url = checkout.get_checkout_url(请求) get_checkout_url 中的文件“/Users/username/work/pythonwork/ecomstore/checkout/checkout.py” 6. 返回 google_checkout.get_checkout_url(request) get_checkout_url 中的文件“/Users/username/work/pythonwork/ecomstore/checkout/google_checkout.py” 27.redirect_url = _parse_google_checkout_response(response_xml) _parse_google_checkout_response 中的文件“/Users/username/work/pythonwork/ecomstore/checkout/google_checkout.py” 46. xml_doc = minidom.parseString(response_xml) parseString 中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/minidom.py” 1924. 返回 expatbuilder.parseString(string) parseString 中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py” 940.返回builder.parseString(string) parseString 中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py” 223. parser.Parse(字符串,真) 异常类型:/cart/ 处的 ExpatError 异常值:不匹配的标记:第 1460 行,第 4 列