11

How can I add retry-header in cherrypy?

  import cherrypy
  import os

  class Root:

    def index(self):
      cherrypy.response.headers['Retry-After'] = 60
      cherrypy.request.headers["Age"]= 20
      cherrypy.config.update({'Retry-After': '60'})

      raise cherrypy.HTTPError(503, 'Service Unavailable')
    index.exposed = True 

    cherrypy.quickstart(Root())

This retry-header dt works.

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93
sam
  • 123
  • 1
  • 5
  • 2
    Just a little suggestion: The common indentation level in python is 4 spaces - you might want to follow it instead of using 2 spaces. – ThiefMaster May 19 '11 at 06:11
  • 3
    ok thanks. can you help me in getting answer of my question? – sam May 19 '11 at 06:16

1 Answers1

26

When you set a status code by raising HTTPError, the headers in cherrypy.response.headers are ignored. Set the HTTP status by setting cherrypy.response.status instead:

import cherrypy

class Root:
    def index(self):
        cherrypy.response.headers['Retry-After'] = 60
        cherrypy.response.status = 503
        # Feel free to return a better error page than the following
        return "<h1>Service Unavailable</h1>"
    index.exposed = True

cherrypy.quickstart(Root())
Pär Wieslander
  • 28,374
  • 7
  • 55
  • 54
  • You're welcome! If the answer solved your problem, please consider accepting it to show others that your question has been answered and to give credit for the answer: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Pär Wieslander May 19 '11 at 06:47