Google Checkout/GAE:urlfetch:XML 解析器错误。序言中不允许出现内容

发布于 2024-12-02 21:58:07 字数 2283 浏览 2 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城半夏 2024-12-09 21:58:07

当字符位于 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/

×纯※雪 2024-12-09 21:58:07

您看到的错误消息是一条非常通用的错误消息,表明您向 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 "<".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文