bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.44k stars 1.46k forks source link

Error handler crashes with redirect #236

Open iurisilvio opened 13 years ago

iurisilvio commented 13 years ago

It happens because redirect exception is not handled by Bottle, because it already get an exception (404).

import bottle

@bottle.error(404)
def error_route(code):
    bottle.redirect('/')

bottle.debug(True)
bottle.run(reloader=True)

I get this exception:

<pre>HTTPResponse('HTTP Response 303',)</pre>
<h2>Traceback:</h2>
<pre>Traceback (most recent call last):
  File "/tmp/t/bottle.py", line 788, in wsgi
    out = self._cast(self._handle(environ), request, response)
  File "/tmp/t/bottle.py", line 741, in _cast
    out = self.error_handler.get(out.status, repr)(out)
  File "a.py", line 5, in error_route
    bottle.redirect('/')
  File "/tmp/t/bottle.py", line 1748, in redirect
    raise HTTPResponse("", status=code, header=dict(Location=location))
HTTPResponse: HTTP Response 303
</pre>
iurisilvio commented 13 years ago

Just to link things, it is reported in googlegroups: https://groups.google.com/d/topic/bottlepy/RQV3B7ACiNk/discussion

ZoomQuiet commented 12 years ago

Yep! Me 2!

get this error:

AttributeError("'Bottle' object has no attribute 'redirect'",)

else usage:

redirect('/index')

(in the same application) get:

 File "/usr/local/bin/bottle.py", line 1812, in redirect
 raise HTTPResponse("", status=code, header=dict(Location=location))
    HTTPResponse: HTTP Response 303

not fixed the BUG?! i had to jump as:

    response.set_header('location', "/tag/%s/info"% tid)
    response.status = 303
lenormf commented 3 years ago

Bump.