Catching Django Errors When Client Is Not A Web Browser? - django

I'm building a Django web service that is called from an application. When it throws an exception, I can't see the Django debug page, and can't get to it because the calling application doesn't behave like a web browser (and I don't have control over that application).
Is there a way to redirect the Django error page to a a log file rather than to the calling client, possibly via changing the FastCGI config (I'm using lighty + FastCGI)? Or maybe a "dump to file" config option or some sort of LogExceptionToFile() method within the framework itself?

You might try just creating custom ExceptionMiddleware. Just change the process_exception method to log the exception and request data somewhere.
Here's an example: http://www.peterbe.com/plog/who-was-logged-in-during-a-django-exception

If the exception in the django app is not caught, and DEBUG = True, then the exception should be sent to the client.
Some options to help you get debugging info:
Enable and configure logging
Set up email error reporting
Use something like Wireshark to inspect the HTTP request and responses.

Related

django error reporting request url - how to use this locally?

I have a django project which used the normal email admins on an unhandled exception when debug is set to False. ie in production.
I normally just review the error message and the stack trace. However I clicked on the request url link, which managed to recreate the error on the prouduction site (which then fired off another email).
What is this request url? Does it recreate the full http request (including the session etc..) which resulted in the original error?
Can I get the link to point to a local version of the site? (As after fixing a previous error clicking on the earlier request url has manged to create a recent error that we have been unable to reproduce, so it would be good to recreate this locally so it can be debugged.

Removing powered by Jetty

I am using Jetty server with embedded web app. However, whenever I hit any resource which is not present it serves a default page which shows a message "Powered by Jetty".
This page is being served from org.eclipse.jetty.server.handler.DefaultHandler.handle.
I want write a custom handler for this, however while trying to register custom Handler in jetty.xml file, I am getting syntax exception and server doesn't start anymore.
I was able to resolve this issue by doing some tweaks along with changes mentioned in Deactivate Jetty's default 404 error handler.

How can I get uncaught exceptions to appear in the Django log

When there are uncaught exceptions in my Django project the log only shows a simple "HTTP 500" message. The HTTP response will contain the full stack trace as HTML but this is not very useful when I am developing web services not being consumed by a web browser. How can I get the full stack trace of uncaught exceptions to appear in the Django log?
I have tried installing custom middleware with a "process_exception" method and custom signals handler for the "got_request_exception" event but neither of these handlers ever got invoked.
I am using Django 1.6.1 and Tastypie 0.11.0 and I'm running in debug mode.
In your django settings set:
DEBUG_PROPAGATE_EXCEPTIONS = True
TASTYPIE_FULL_DEBUG = True
Setting both of these options will allow Tastypie exceptions to propagate upwards.
https://docs.djangoproject.com/en/3.2/ref/settings/#debug-propagate-exceptions
http://django-tastypie.readthedocs.org/en/latest/settings.html#tastypie-full-debug

Azure Web Site with Django 500 Error

I've spent over 8 hours trying to get this Django site up and running on an Azure Website. I've nearly thrown in the towel would really appreciate some help.
So far I have tried numerous methods and followed different tutorials, but they have all yielded the same result. Here is the most recent tutorial I have followed: http://www.windowsazure.com/en-us/develop/python/tutorials/web-sites-with-django/
Now that my site is "up", I am seeing a 500 error for all requests. Here is the error in the log:
The page cannot be displayed because an internal server error has occurred.
Most likely causes:
IIS received the request; however, an internal error occurred during
the processing of the request. The root cause of this error depends on which mo
dule handles the request and what was happening in the worker process when this
error occurred. IIS was not able to access the web.config file for t
he Web site or application. This can occur if the NTFS permissions are set incor
rectly. IIS was not able to process configuration for the Web site o
r application. The authenticated user does not have permission to u
se this DLL. The request is mapped to a managed handler but the .
NET Extensibility Feature is not installed.
Things you can try:
Ensure that the NTFS permissions for the web.config file are correct
and allow access to the Web server's machine account. Check the ev
ent logs to see if any additional information was logged. Verify the p
ermissions for the DLL. Install the .NET Extensibility feature if th
e request is mapped to a managed handler. Create a tracing rule to tra
ck failed requests for this HTTP status code. For more information about creatin
g a tracing rule for failed requests, click here.
Please help!
I got it working by settings up a new django project from the azure gallery and changed some configs and such.
Edit: The configs I updated was just the name of my app. In my case I also updated the database config with the database I wanted to use in settings.py.
The lesson learned from this is that it is easier to initialize the app from Azure's "Create from gallery" feature, and then pull down the source and modify it via ftp or git to achieve the desired project structure/naming.

How can I make hoptoad in Django 1.2 log errors to log file as well as send airbrake notifications?

We're using django 1.2.7 and the hoptoad logging middleware (hoptoad.middleware.HoptoadNotifierMiddleware).
When an error occurs, the error message gets sent to airbrake, but it does not seem to get logged to the django log file. It seems like it's intercepted by hoptoad exclusively.
Does anyone know how to also get the errors logged to the local django log file on disk? I couldn't find any such option in the hoptoad documentation.
Is there a custom modification needed to the hoptoad middleware class?