Responding to web request with python

S

scott212

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!
 
T

Tim Roberts

scott212 said:
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 misunderstanding 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.
 
C

Christopher David Kyle

You must be misunderstanding 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.

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,newline" 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.write("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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top