My server is out in production, and I am running django on top of twisted.
I have the following for logging:
log.startLogging(sys.stdout)
...
reactor.listenTCP(DJANGO_PORT, server.Site(wsgi_root, logPath=os.path.join('./log', '.django.log')))
However, I am only seeing these in my .django.log.X files:
127.0.0.1 - - [25/Nov/2010:16:48:22 +0000] "GET /statics/css/xxx.css HTTP/1.1" 200 1110 "http://www.xxx.com/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"
I know for a fact that registration is throwing a lot of errors, but then the log has NOTHING about the exceptions and errors being thrown!
How can I actually output errors generated by the WSGI file?
Note: I think it has something to do with the fact that I have to change log.startLogging(sys.stdout). However, if the solution indeed is to change that, I would like to know how I can output to BOTH sys.stdout as well the file.
Django doesn't use Twisted's logging APIs. twisted.python.log.startLogging only configures Twisted's logging system. Django probably uses the stdlib logging module. So you'll have to configure that in order to get Django log output written somewhere useful. You see the request logs in your .django.log.X files because those are logged by the Twisted HTTP server, independently of whatever Django logs.
Related
I am trying to get website source in python. My code is like:
import urllib2
url = urllib2.urlopen("http://kolekcjoner.nbp.pl")
I have problem with this one website - expect this website, everything is working ex. google or anything else. What is funny, I was fetching data from this website 3 days ago, but now this code is not working. Why? What has changed?
the problem is that you are trying to get a page that don't exist...
as you can see the error is:
urllib2.HTTPError: HTTP Error 404: Not Found
you can use try and except or use another module that will not raise an exception each time that there is a HTTP error code (like the requests module)
update: after checking a bit I found that in the browser the address that you gave works properly so just for the requests sent by python it gave 404, this means that the server is checking the user agent of the requests and if the user agent isn't allowed/known the server will return an error code (e.g 404). so I checked if that is true by changing the user agent field:
>>> requests.get("https://kolekcjoner.nbp.pl/")
<Response [404]>
>>> requests.get("https://kolekcjoner.nbp.pl/",headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103'})
<Response [200]>
I hope that this helps you (anyway you should know that the robot.txt of this site disallow any robot to check this site...)
I have just deployed a Mezzanine instance on Elastic Beanstalk and all is working fine when DEBUG = True.
When DEBUG = False however, I am bounced to the 500 error page whenever I am in the admin section of the site and "Save" something (a page, or blog for example). Other than that, the rest of the site works perfectly - it's reading everything from the database, serving up compressed JS/CSS etc.
Things I have already checked:
- ALLOWED_HOSTS is now set correctly
- There are no console errors for missing JS files
- The log file just shows what is below:
172.31.17.189 (73.222.4.136) - - [08/Jun/2016:04:09:35 +0000] "POST /admin/blog/blogpost/1/change/ HTTP/1.1" 500 6317 "http://tenzo-www.us-west-2.elasticbeanstalk.com/admin/blog/blogpost/1/change/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
I'd welcome thoughts. Perhaps you can just even tell me how to get better logging while DEBUG=False? I don't see anything in access_log or error_log that's saying anything about this error.
Actually managed to fix my own problem - two fold answer:
1) To enable better debugging while DEBUG=False, I suggest the following in your settings.py:
SERVER_EMAIL = 'server#xxx.com'
ADMINS = (('Name', 'xxx#xxx.com'),)
SEND_BROKEN_LINK_EMAILS = True
Then you'll get a nice email showing you the error!
2) The actual error was caused because django-htmlmin doesn't play nice with Mezzanine. It adds content around the response that breaks it.
Hope it helps someone.
I've just installed my app on a new server to test something out. Setup all went smoothly, app is running fine with a local mysql database behind it which is fully synced up. The only problem is I can't log in.
I've tried logging in via my frontend, and via the admin. For both, if I enter incorrect details it shows an error message. If I enter correct details it doesn't, but still throws me back to the login page.
There is nothing in the logs to suggest what's going on, all I get in a runserver log is something like:
[26/Jun/2013 15:09:31] "POST /account/login/ HTTP/1.0" 302 0
[26/Jun/2013 15:09:31] "GET /dashboard/ HTTP/1.0" 302 0
[26/Jun/2013 15:09:31] "GET /account/login/?next=/dashboard/ HTTP/1.0" 200 2537
I'm clearly logging in ok, being redirected to the dashboard, then bounced straight back to login.
I'm stumped as to where to start looking to debug this problem. The same setup is running fine elsewhere. Can anyone give me any clues as to where to start looking?
You might check the value of SESSION_COOKIE_SECURE. If set to True, the admin login form will simply redirect to itself. Also check that SESSION_COOKIE_DOMAIN is correct. I don't know how many times I've done this inadvertently in development :)
I'm running a site using Django in a shared environment (Dreamhost), but 1.4 in a local environment.
Somtimes, I get hit by many, many Apache dummy connections (e.g., [10/Jul/2012:00:49:16 -0700] "OPTIONS * HTTP/1.0" 200 136 "-" "Apache (internal dummy connection)"
), which makes the site non-responsive (either it gets killed for resource consumption or max connections).
This does not happen on other sites on this account (though none are running Django). I'm trying to figure out a way to prevent this from happening, but I'm not sure what trouble-shooting process to use. Guidance on process or common sources of this issue would be useful.
Try:
<Limit OPTIONS>
Order allow,deny
Deny from all
</Limit>
This would cause a 403 forbidden to be returned by Apache and would not be handed off to any Django application if the issue is that they are getting through to the application at the moment.
I realize this is more of a server question (since all media requests bypass Django via NGINX), but I want to know how others Django Developers have been doing this, more so than I care to understand only the specifics of how to do it in NGINX. I don't care about the bandwidth of HTML page requests via Django; only the bandwidth of static media files. Are those of you out there using Django and its DB to do this, or are you using web server-specific methods to do this? If the latter is the case, I'll head over to ServerFault.
I want to do this so I can measure the bandwidth usage on a per-subdomain (or similar method) basis.
Sorry about non-django approach but as we speak about static files that in good practice get passed through without ever hitting the wsgi or whathaveyou.
Apache access logs have request size in them, so what you could do is grep out your media files and directories (cat access_log|grep "/images/\|/media/thumbs/\|jpg) and parse/sum that number with regexp and/or awk. Here's example access log entry (45101 being the file size):
10.0.0.123 - - [09/Sep/2010:13:30:05 -0400] "GET /media/images/mypic.jpg HTTP/1.1" 200 45101 "http://10.0.0.123/myapp" "Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11"
That should get you going..