0

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>"
  • Sounds like your XML isn't well-formed. How are you generating it? Look for stray characters around the start of the string. – bobince Sep 03 '11 at 08:04
  • Updated with XML that I am sending. This passed the validator earlier. Is there still some error? Thanks again. – user926385 Sep 03 '11 at 17:50

2 Answers2

0

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

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thanks for your response. Appreciate it. Updated with XML that I am sending. This passed the validator earlier. Is there still some error? Thanks again. – user926385 Sep 03 '11 at 17:51
0

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/

Mihai Ionescu
  • 2,108
  • 1
  • 12
  • 15
  • Thanks. Other comments also answered the question. The link at the end of the post was very helpful. On looking closely, there was 'XML=' in received XML as opposed to just ''. So there was extra 'XML=' and hence the error. Thanks again to everyone for answering. Greatly appreciate it. – user926385 Sep 04 '11 at 05:34