1

I'm trying to dynamically generate iCal output using Max M's icalendar python module and google's app engine. However, when I omit the boiler plate <html> header and footer tags on the output from webapp.RequestHandler, it looks like the HTTP 200 response is added to the top of the file.

When I register this code:

class Calendar(webapp.RequestHandler):
    def get(self):
        self.response.out.write('BEGIN:VCALENDAR\n')
        [...]

with webapp.WSGIApplication, the response looks like:

Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 11133

BEGIN:VCALENDAR
[...]

How do I omit the <html> tags and not get the HTTP 200 response splatted at the top of the page?

1

5 Answers 5

3

Webapp and App Engine don't care what content type you return, so the issue is unrelated to the tag (or lack thereof). You likely have a print statement somewhere in your code, which is causing the headers to be sent as part of the body of the response. You should never use print in a WSGI app - always use self.response.out.write as in the snippet you pasted.

Sign up to request clarification or add additional context in comments.

Comments

2

You can't, the "Status: 200 Ok....." is the HTTP header which will be outputted on every request by the web server. Any web server will do the same thing.

Your client will need to read the body of the http response.

2 Comments

[I am a web page noob, but] I thought that even though the HTTP header was sent to the client that it would be intercepted by the browser and the rest of the text would pass to the browser. For example, if I do "view source" on this page, I don't see the HTTP header response. It starts with <!DOCTYPE ... So perhaps I should ask, how can I generate a dynamically generated file without the HTTP header stuff.
As Nick said in his answer, you probably have a print statement somewhere in your code if you're seeing the header data being outputted in your browser. If you remove all print statements you won't get the header being outputted in your browser.
1

Not sure if this is the real problem or not, but you should be setting the content-type to indicate that this is calendar data, not HTML:

Content-Type: text/html; charset=utf-8

should be

Content-Type: text/calendar;

Comments

0

This seems to be outputting standard HTTP response headers. Try adding "Content-Disposition: attachment; filename='%s'" % filename HTTP header to your response to get desired file downloaded.

1 Comment

Unfortunately, doing that inserts Content-Disposition: attachment; filename='cal.ical' between the HTTP 200 response and the calendar. It doesn't nuke the HTTP 200 text.
0

Something else to consider:

If you are importing code from another file, and that other file is a webapp, you need to make sure that it only runs as a webapp if it is the main

Anotherwords - Go from this

application = webapp.WSGIApplication(
                                 [
                                  ('/locate', Request),
                                   ],
                                 debug=False)

util.run_wsgi_app(application)

to this

application = webapp.WSGIApplication(
                                 [
                                  ('/locate', Request),
                                   ],
                                 debug=False)

def main():
   util.run_wsgi_app(application)

if __name__ == "__main__":
   main()

This problem was killing me for hours, and this was one of the only posts I could find that was close to it. I'm hoping this will help anyone else with the same problem as me!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.