By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

Responding to web request with python

P: n/a
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!
Nov 1 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
scott212 <bu*******@gmail.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 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.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 2 '08 #2

P: n/a
On Sun, 2 Nov 2008, Tim Roberts wrote:
scott212 <bu*******@gmail.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 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.
--
Tim Roberts, ti**@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,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
Nov 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.