Google Checkout/GAE:urlfetch:XML 解析器错误。序言中不允许出现内容
使用 XML 更新了问题。我之前用验证器检查过它并通过了。问题可能是别的什么。再次感谢。
您能让我知道以下代码有什么问题吗?我用它来提交服务器到服务器结账 API 请求。
我不断收到错误:“解析 XML 时出错;来自解析器的消息是:序言中不允许内容”。
我已尝试了所有排列和组合,并且还搜索了网络,但无法获得任何线索,我将非常感谢您的及时帮助,
谢谢。 .阿什什 PS:为了安全起见,下面用于身份验证的 Base64 编码值经过修改,因此只是一个随机值。
XML = "..."
form_fields = {'XML': XML}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch( url='https://sandbox.google.com/checkout/api/checkout/v2/merchantCheckout/Merchant/MERCHANT_ID', payload= form_data,
method=urlfetch.POST,
headers={"Authorization": "Basic Kfgoijkef3fdgikneijerfererererwetfni43rfeferr=",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/xml;charset=UTF-8"
}
)
XML = "<?xml version='1.0' encoding='UTF-8'?> \
<checkout-shopping-cart xmlns='http://checkout.google.com/schema/2'> \
<shopping-cart> \
<items> \
<item> \
<item-name>HelloWorld 2GB MP3 Player</item-name> \
<item-description>HelloWorld, the simple MP3 player</item-description> \
<unit-price currency='USD'>159.99</unit-price> \
<quantity>1</quantity> \
</item> \
</items> \
</shopping-cart> \
<checkout-flow-support> \
<merchant-checkout-flow-support> \
<shipping-methods> \
<flat-rate-shipping name='SuperShip Ground'> \
<price currency='USD'>9.99</price> \
</flat-rate-shipping> \
</shipping-methods> \
</merchant-checkout-flow-support> \
</checkout-flow-support> \
</checkout-shopping-cart>"
Updated question with the XML. I checked it with a validator earlier and it passed. Could the issue be something else. Thanks again.
Could you pls let me know what is wrong with the following code? I am using it for submitting a Server-to-Server Checkout API Request.
I keep getting the error: "Error parsing XML; message from parser is: Content is not allowed in prolog'.
I have tried all permutations and combinations, and also searched on web but could not get any leads. Your prompt help will be greatly appreciated as I am stuck.
Thank you.
.Ashish
PS: the base64encoded value below used for authentication is modified below for security and hence is just a random value.
XML = "..."
form_fields = {'XML': XML}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch( url='https://sandbox.google.com/checkout/api/checkout/v2/merchantCheckout/Merchant/MERCHANT_ID', payload= form_data,
method=urlfetch.POST,
headers={"Authorization": "Basic Kfgoijkef3fdgikneijerfererererwetfni43rfeferr=",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/xml;charset=UTF-8"
}
)
XML = "<?xml version='1.0' encoding='UTF-8'?> \
<checkout-shopping-cart xmlns='http://checkout.google.com/schema/2'> \
<shopping-cart> \
<items> \
<item> \
<item-name>HelloWorld 2GB MP3 Player</item-name> \
<item-description>HelloWorld, the simple MP3 player</item-description> \
<unit-price currency='USD'>159.99</unit-price> \
<quantity>1</quantity> \
</item> \
</items> \
</shopping-cart> \
<checkout-flow-support> \
<merchant-checkout-flow-support> \
<shipping-methods> \
<flat-rate-shipping name='SuperShip Ground'> \
<price currency='USD'>9.99</price> \
</flat-rate-shipping> \
</shipping-methods> \
</merchant-checkout-flow-support> \
</checkout-flow-support> \
</checkout-shopping-cart>"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当字符位于 XML 文档类型声明之前或非标准字符(在 HTML 中有效)出现在 XML 声明中时,“序言中不允许内容”错误是 XML 解析器生成的错误。也可能是由于指定大写字母的编码引起的(例如UTF-8 不正确)。
尝试将编码更改为“utf-8”,看看是否可以解决问题。
当出现此错误时,下面的链接有更多有趣的情况:
http://www.judahfrangipane.com/blog/2006/12/13/content-is-not-allowed-in-prolog/
The "Content is not allowed in prolog" error is an XML parser generated error when characters are located before the XML document type declaration or non-standard characters (that are valid in HTML) appear in the XML declaration. It can also be caused by specifying the encoding in capital letters (e.g. UTF-8 is incorrect).
Try changing the encoding to "utf-8" to see if that fixes it.
The link below has more interesting cases when this error shows up:
http://www.judahfrangipane.com/blog/2006/12/13/content-is-not-allowed-in-prolog/
您看到的错误消息是一条非常通用的错误消息,表明您向 XML 解析器提供的内容不是格式良好的 XML。它可能意味着文件为空,或者以无法识别的字节顺序标记开头,或者以“<”以外的其他内容开头。
The error message you are seeing is a very general-purpose error message saying that what you have given the XML parser is not well-formed XML. It can mean that the file is empty, or starts with an unrecognised byte-order mark, or starts with something other than "<".