Question

thanks to Michael Merickel I was able to globally redirect an ip address. I could have added this as a comment but decided on another question. His code gives the user an error message. I'd like to also receive an alert when this happens. I did it by a simple print statement but it (annoyingly) prints the message twice. I'm only making 1 request on a simple view (no css files, no js, etc). Is it actually requesting it twice?

@subscriber('pyramid.events.NewRequest')
def newrequest(event):
    request = event.request
    if request.remote_addr.startswith('66.'):
        print 'hey, we got one...', 
        raise SomeException('my custom message')

@view_config(context=SomeException, renderer='string')
def exc_view(exc, request):
    print 'and another'
    return exc.message


Result:
hey, we got one...and another
hey, we got one...and another # why the extra line?
Was it helpful?

Solution

If you're in a web browser then it's probably a request for the favicon. You can check this by printing out the requested url.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top