Responding to web request with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • scott212

    Responding to web request with python

    I'm responding with xml to a web request from google checkout but I
    think I'm in a catch-22. To get my webserver (apache) to respond I
    need a header and then a blank line before my xml begins, or else it
    throws the 500 error. If have the blank line before the xml, the
    service I'm responding to cannot parse it. If it's a response, can I
    still use urllib or something like that? Is that my answer?

    Thanks for all your help!
  • Tim Roberts

    #2
    Re: Responding to web request with python

    scott212 <busitones@gmai l.comwrote:
    >
    >I'm responding with xml to a web request from google checkout but I
    >think I'm in a catch-22. To get my webserver (apache) to respond I
    >need a header and then a blank line before my xml begins, or else it
    >throws the 500 error. If have the blank line before the xml, the
    >service I'm responding to cannot parse it. If it's a response, can I
    >still use urllib or something like that? Is that my answer?
    You must be misunderstandin g something. The HTTP protocol REQUIRES that
    the headers and the content be separated by a blank line.

    Perhaps you should try to use a debug proxy to intercept the exact text of
    the response, just to make sure you're sending what you think you are
    sending.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    • Christopher David Kyle

      #3
      Re: Responding to web request with python

      On Sun, 2 Nov 2008, Tim Roberts wrote:
      scott212 <busitones@gmai l.comwrote:

      I'm responding with xml to a web request from google checkout but I
      think I'm in a catch-22. To get my webserver (apache) to respond I
      need a header and then a blank line before my xml begins, or else it
      throws the 500 error. If have the blank line before the xml, the
      service I'm responding to cannot parse it. If it's a response, can I
      still use urllib or something like that? Is that my answer?
      >
      You must be misunderstandin g something. The HTTP protocol REQUIRES that
      the headers and the content be separated by a blank line.
      >
      Perhaps you should try to use a debug proxy to intercept the exact text of
      the response, just to make sure you're sending what you think you are
      sending.
      --
      Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.
      >
      I agree with Tim, check the output. I had the same issue while serving up
      GIF images generated on the fly. I was sending two blank lines before the
      image data since an extra newline was being automatically added by the
      "print" statement.

      # Print the header information
      print "Content-type: image/gif\n\n"

      The above fails since it sends: "header,newline ,newline,newlin e" with the
      last newline appended by the print statement. A solution would have been
      to simple remove one of the my coded newline characters and let the print
      statement add the second one. However, I switched to "write" statements so
      I could _see_ the newline characters in my code.

      import sys
      # Write out the header information
      sys.stdout.writ e("Content-type: image/gif\n\n")

      The above worked because "write" does not add an automatic newline
      character to the output.

      Also, make sure your content-type is correct. The same content would be
      handled differently by a browser depending on how it is identified.

      "Content-type: text/html" - Sent through the HTML parser then displayed.
      "Content-type: text/plain" - Displayed without formatting.

      What is the application you're communicating with looking for?

      Hope that helps,
      Christopher


      Comment

      Working...