python - Webpy: how to set http status code to 300 -


maybe stupid question cannot figure out how http status code in webpy.

in documentation can see list of types main status codes, there generic function set status code?

i'm trying implement unapi server , it's required reply 300 multiple choices request identifier. more info here

thanks!

edit: discovered can set through web.ctx doing

web.ctx.status = '300 multiple choices'

is best solution?

the way web.py 301 , other redirect types subclassing web.httperror (which in turn sets web.ctx.status). example:

class multiplechoices(web.httperror):     def __init__(self, choices):         status = '300 multiple choices'         headers = {'content-type': 'text/html'}         data = '<h1>multiple choices</h1>\n<ul>\n'         data += ''.join('<li><a href="{0}">{0}</a></li>\n'.format(c)                         c in choices)         data += '</ul>'         web.httperror.__init__(self, status, headers, data) 

then output status code raise multiplechoices in handler:

class myhandler:     def get(self):         raise multiplechoices(['http://example.com/', 'http://www.google.com/']) 

it'll need tuning particular unapi application, of course.

see the source web.httperror in webapi.py.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -