Debugging Django when no Debug info is displayed | Django - python

I'm serving an app through IIS6. An error is occurring preventing the app from working, I am not 100% sure what it might be.
I believe the following is generated by python, but I am not entirely sure.
"A server error has occurred. Please contact the administrator"
Any ideas on figuring out what is actually going on?

It looks more like web server error (500?).
Is debugging enabled? You should be able to see exception message and traceback. Also, check web server error log and define settings.ADMINS. This is usefull in production when debugging is disabled:
When DEBUG=False and a view raises an exception, Django will e-mail these people with the full exception information.

http://docs.python.org/library/logging.html#simple-examples
import logging
logging.debug('foobar')

Related

Django is sending me an email about "Invalid HTTP_HOST header"

I have website that using django on DigitialOcean. Django is sending me an email with title Invalid HTTP_HOST header: 'url.ml'. You may need to add 'url' to ALLOWED_HOSTS. But I don't want to add this, I added my own domains and ip address.
I have list of questions
Why is django sending me this email?
Bots are attacking to my site?
If so how they do that?
How can I prevent this?
As specified in the docs,
When DEBUG is False, Django will email the users listed in the ADMINS
setting whenever your code raises an unhandled exception and results
in an internal server error (HTTP status code 500). This gives the
administrators immediate notification of any errors. The ADMINS will
get a description of the error, a complete Python traceback, and
details about the HTTP request that caused the error.
So, I guess email comes from this. If your are interested in getting more detailed trace on 500 errors, you can have a look on Sentry, which his quite useful.
Now, regarding your error: url.ml I can't find any IP on this domain, but it's quite easy to had this header manually.
If you want to go deeper, you can go check your NGINX Log, aiming for IP sending those kind of requests: It might be some kind of DigitalOcean monitoring utilities, some kind of attack, you will need to get more details about that.

"Internal Server Error" with POST requests on flask + gunicorn + nginx setup

I am attempting to deploy a flask webapp on digital ocean, but I keep getting "internal server error" whenever I attempt to do anything involving POST requests (such as logging in or registering). The app works fine when I run it using flask's built-in server.
I used parts 1 & 2 in this tutorial to set it up, with the exception of replacing flask_project with the name of my project, and newuser with my username. Does anybody know how I can fix this, or at the very least, go about diagnosing the problem? Are there error logs somewhere?
I notice the sample app used in the example only uses GET requests, which work fine. My guess is that I need to do configuration slightly differently in order to get POST to work as well. However, I can't find any tutorials on how to properly do this.
Thanks in advance
Update: So I wiped the sever clean and started over, this time using this tutorial on how to deploy on apache. Still having the same problem.

OAuth fails after deploying google glass application

I went through the instructions on for the Google Glass Python Quick Start. I deployed the app and the app supposedly finished deploying successfully. I then went to the main URL for the app and attempted to open the page. The page asked me which Google Account I wanted to use to access the app, and I chose one. It went through some type of redirect and then came back to my app and tried to open up the openauth2callback page at which time nothing else happened. It just stopped on the openauth2callback page and sat there whitescreened.
I assume that the app is supposed to look like the sample app that was posted where I should see timeline cards and be able to send messages, but I don't see any of that.
I checked my oauth callbacks and they look exactly like the quick start instructions said to make them. What am I missing?
A couple of things that are standard debugging practices, and you may want to update the original question to clarify:
Did OAuth actually fail? What information do you have that it failed? Can you verify from web server logs that the callback URL was hit and that it contained non-error return values?
Can you check your web server and app server logs to see if there are any error messages or exceptions logged?

Auth_token error at Facebook

i have been on this for the last 2 days with no result.
i am running my facebook app on my localhost with port-forwarding method.
i know my server setup is working fine as i can see the logs on the django runserver and dyndns log as well.
django is properly responding to calls as well.
the problem is as soon as the app authorizes with my user account, it straight follows to the page that says this:
Errors while loading page from application
The URL http://amitverma.dyndns.org/facebook_sample/?auth_token=817f8fbe99eff10582b634589de17b84 is not valid.
Please try again later. We appreciate your patience as the developers of app_test and Facebook resolve this issue. Thanks!
I am making a test app learning from facebook + django tutorial from here and here.
I am still getting this error and I have no idea what i am doing wrong...
Please help me out.
This often happens with a failed authentication. I'm not sure what the Python client libraries might look like, but with the PHP ones you generally make an authorization call against the library, something like $facebook->require_login().
With the PHP library, if this call fails to verify the user's Facebook session, then it automatically outputs HTML that will redirect the browser and try to re-establish the session, hence the auth_token parameter.
I suspect you're running into something similar. Try to isolate any authentication calls you're making, and use a Firefox extension like LiveHTTPHeaders to see if you are undergoing any redirects during the requests.
When you get that error, presuming you have debug=True in the Django settings and that your application is in development mode in Facebook, you can do View Source and see the entire Django error page that would normally display, including traceback. Facebook comment it out in the HTML so it doesn't show on the front end, but you can copy and paste it into a separate HTML file and view that in your browser to see the nice friendly Django error page which will definitely give you a clue as to what's going wrong.

How can I see error logs of Django views

I'm coding a small application with Django. But I can't see any error logs in the console when an error (e.g. Python syntax error, etc.) occurs in one of my views -no action at all.
How can I see the error logs of my views? Debugging like a blind is really annoying.
Django does not print any errors to the console by default. Instead it provides very helpful error pages that are displayed for any errors that occur in your views. Please check what your DEBUG setting is set to. In development this should be True which will give you the nice error pages for 404 and 500 errors.
The pretty error page will look like this:
(source: linkaider.com)
I can also recommend the talk What the Heck Went Wrong? from DjangoCon2009 for some more information on basic debugging technics with django.

Categories

Resources