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>"
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/