Using Python on Dreamhost, return XML document (not HTML) -


This indicates that a Python script should print the HTML type declaration as the first line of output. However, I need to prepare an XML response for third-party APIs. Here's what I've tried:

  • Set the type of announcement to XML Dreamhost throws an error when I do so.

  • HTML type type declaration, after an XML type declaration

    How do I surround this limit Can work?

    The page you linked has a relevant sentence:

    If you want to see the printed output from your Python code, you will need to print the print "Content-Type: Text / HTML \ n \ n" as the first line of output.

    Note the first part - "If you want to see printed output." It is only a requirement that you expect to be able to display your output as a web browser HTML. You can also return image / gif, audio / mpeg, or any other valid mime type.

    When I do this, Dreamhost throws the error.

    Do you have something of that? Or does your browser display an error because it received a content-type, do not know what to do with it?

    (followup)

    I have verified that XML output actually works as well as by uploading the following simple Python CGI prints to my "Content-Type: Text / XML" Print '& lt ;? Xml version = "1.0" on encoding

      #! / Usr / bin / python def main = "UTF-8"? & Gt; Print '& lt; Birth of a person = "1 912/06/23" = "1954/06/07" & gt; Print '& lt; Name & gt; Alan Turing & lt; / Name & gt; Print '& lt; / Person & gt; If __name__ == "__main__": main ()   

    Testing it with curl, I get:

      Macintosh: ~ Sheram $ Curl -i http: //tests.shermpendley.com/person.py HTTP / 1.1 200 OK Date: Mon, 28 Mar 2011 00:14:50 GMT Server: Apache Variation: Accept Encoding Content-Length: 124 Content-Type: Text / xml & lt;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Birth of a person = "1 912/06/23" = "1 947/06/07" & gt; & Lt; Name & gt; Alan Turing & lt; / Name & gt; & Lt; / Person & gt;   

    To diagnose "500 server error", check your error log. Connect with your account (SSH, SFTP, FTP - whatever you usually do to manage your files) and "/home/{username}/logs/{sitename}/error.log "For example, when I have an intentional introduction syntax error above, then tried to bring it with curl, I got the error. The following in the log:

      [Sun March 27 17: 18:10 2011] [Error] [Client 98.236.96.39] File "person.py", line 3 [Sun March 27 17:18:10 2011] [ Error] [customer 98.236.96.3 9] fake! [Sun March 27 17:18:10 2011] [Error] [Client 98.236.96.3 9] ^ [Sun March 27 17:18:10 2011] [Error] [Client 98.236.96.3 9] Syntax Error: Invalid Syntax [Sun 26 March 17: 18: 10 2011] [Error] [Client 98.236.96.3 9] Premature End of Script Header: person.py    

Comments