To fetch a 500 error I used webapp2 to show a custom error page : http://webapp-improved.appspot.com/guide/exceptions.html#exceptions-in-the-wsgi-app.
This page is always shown when an error occurs. Even when there is an over_quota error and app.yaml is correctly configured.
How can i show a custom page for Quota_over Error ?
In app.yaml:-
error_handlers:
- error_code: over_quota
file: over_quota.html
The code for quota over in App Engine is 503. So, you can create a handler that handles specifically the 503 error code.
Related
I am trying to set up SAML Single Sign-On (SSO) with my Django app, but I am getting an error when I try to login to my app.
I go to the app url, Microsoft processes the request (the url displays microsoft.loginonline.com/etc briefly), and then I get redirected to this page:
https://my-app.azurewebsites.net/.auth/login/aad/callback
which displays this error:
{"code":400,"message":"IDX10501: Signature validation failed. Unable to match keys: \nkid: '[PII is hidden]', \ntoken: '[PII is hidden]'."}
The reply url is set to:
https://my-app.azurewebsites.net/.auth/login/aad/callback
I did the set-up following both the Azure docs and following this documentation: https://django-auth-adfs.readthedocs.io, it's ostensibly working on my localhost, just not on the actual azure app service... I am unsure of what I am doing wrong, and the error message is not very informative for me as I am new to back-end programming and cloud.
Any help is appreciated, thanks!
As stated by you, you have configured SAML SSO with Django app in the backend and encountering the said error while logging in. As per the error reported, the ‘PII value is hidden’ due to which the signature keys couldn’t be validated by the AAD. So, you will need to add some strings to your ‘settings.py’ file to notify the Django web app the returned value of token from AAD. Please find the below strings to be added to the respective file: -
Please add the below string to AUTHENTICATION_BACKENDS section in ‘settings.py’ file.
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
After adding the above string to the said file, the app should work and so the SSO too.
Also, please find the below link to a similar thread for your reference: -
JWT token authentication fails with message "PII is hidden"
Thanks
In my django app, I have multiple places where I raise a specific custom exception DeserializationError. My goal is to show/redirect to a pretty page to show the user this error, including the error message, when this error is raised. Basically, a page that says something like
Something went wrong. Please contact webmaster#email.com.
Error: DeserializationError. Message: SomeModel, "somemodel", does not exist.
Would this even be possible? I've been trying to search for a solution but haven't been able to find anything yet.
Most likely such errors will return HTTP 500 server error.
In django you can write your own custom view to handle such cases and return your own page with the html that you like.
The 500 (server error) view explains writing server error views. There are more types of errors handled as explained on same page.
An option for handling HTTP 500 errors, add this to your Settings file,
handler500 = 'mysite.views.my_custom_error_view'
and in the view, you can render the "error page" using
HttpResponseNotFound('<h1>Page not found</h1>')
the server_error() view will be overridden by handler500.
In my Flask app, I set up a 404 handler like this:
#app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
However, when a user goes to an unrecognized URL, the system gives an internal server error instead of rendering my 404 template. Am I missing something?
Internal Server Error is HTTP error 500 rather than 404 and you haven't added error handler for it. This occurs when the server is unable to fulfill the client request properly. To add a gracious message when such error occurred, you can add a errorhandler like 404.
#app.errorhandler(500)
def exception_handler(e):
return render_template('500.html'), 500
There is likely an issue while rendering the 404 template which then triggers an internal server error.
I suggest checking the logs for your app.
This will also occur if you have debug set to true. Try setting debug to false and see if your custom 404 shows up then.
For a Google Appengine project written in Python, I want to have my own error messages when an error occurs. I want to use the error_handlers as described in:
http://code.google.com/intl/nl/appengine/docs/python/config/appconfig.html#Custom_Error_Responses
In the application I use webapp with debug = False
When I create an error in my code, I get the standard 500 Server error message from the browser.
I have created a custom error page named default_error.html
The question is: Where to save this custom error page?
BTW This is my app.yaml code:
application: customerrorpage
version: 1
runtime: python
api_version: 1
error_handlers:
- file: default_error.html
handlers:
- url: /good.htm
static_files: static/good.htm
upload: static/good.htm
- url: /
static_files: static/good.htm
upload: static/good.htm
- url: /.*
script: main.py
Defining a custom 404 with just the python part works for me:
app.error_handlers[404] = handle_404
def handle_404(request, response, exception):
c = {'exception': exception.status}
t = jinja2.get_jinja2(app=app).render_template('404.html', **c)
response.write(t)
response.set_status(exception.status_int)
This gives you more control over error messages and other dynamics that you might want to display.
One way to approach this is to define a 'BaseRequestHandler' class, from which your request handlers are subclassed.
The BaseRequestHandler class can override the handle_exception() method (see http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html#RequestHandler_handle_exception) to render an error page.
Partly found how it works. Thank you all for your answers.
The location of the HTM file could be in the core or in a seperate directory. If that's the case use for example the following code in your app.yaml file:
error_handlers:
- file: error_handlers/default_error.html
The to be shown html file should now be placed in the directory error_handlers
When you import an nonexisting module in main.py the above page is shown.
To fetch a 500 error I used webapp2 to show a custom error page. This page is always shown when an error occurs. Even when there is an over_quota error and app.yaml is correctly configured. I also removed webapp2 and used webapp again. Now no page is displayed at all.
I have another app which is currently over_quote. How to get the over_quota html page displayed? Is it a bug?
How do I implement using python if I want to manage the 403 and 404 error, for example, to know which URL is most the 403 or 404 error?
There is no need to do this manually on App Engine. Just take a look at the "Errors" section in the dashboard for your app.
For more information on this, see http://code.google.com/intl/de-DE/appengine/kb/general.html#erroruris