Django application behaves strangely, sometimes works, sometimes doesn't - python

We are building a school information system using Python/Django. The production server runs Ubuntu, Apache2 with mod_wsgi. Recently strange things happen to our server. When we test our code locally everything works well. After deployment the application works, but sometimes returns 'Page not found' or 'Division by zero' errors. Why is this happen, from attack or server configuration, please help us!

Is server running out of memory or disk errors? Do dmesg, and verify for any exceptions or errors reported.
System is compromised? check for /var/log/auth.log
Secure SSH using non standard port or by installing DenyHosts
Scan through syslog for any other error
If any logging is enabled in django, check for errors.
Apache logs in /var/log/apache2 can give details of access details and any errors.
If none of above, please provide more details like configurations/logs from Apache, Syslog.

Related

django devserver can't connect

I have a situation where if I run Apache with wsgi (now uninstalled), a test website works, but running the same server with runserver 0.0.0.0:8080 gives ERR_CONNECTION_REFUSED from local or remote (even with the apache2 service stopped).
Edit: I don't think it's Apache, I've reproduced the problem on a clean server with no Apache installed, so unless Apache somehow modified something under source control it's not that
My knowledge of web details is hazy, I don't even know where to troubleshoot this problem - the devserver runs (runserver prints as expected and doesn't give any errors) but never receives a request, I have nothing in iptables.
Sorry for anyone who read this, it would probably have been impossible to solve given my supplied information.
What had actually happened was that I'd been having to modify my wsgi.py script in order to make it happy inside the Apache server, and I'd added a line which said "os.system('/bin/bash --rcfile )" to try and make sure that when running inside apache it got the virtualenv activated.
This line must have been causing some strange problem, another symptom was that I realised when I was running "runserver", it wasn't crashing the the python process was backgrounding itself, where normally it runs inside that console window.
Thanks everyone who asked questions helping me debug!

script timed out before returning headers openshift

I have a python application (webservice) hosted in Openshift but, a few days ago, the app don't work anymore. The log points to "[error] script timed out before returning headers" and I can't solve this.
Someone can help me?
The solution was remove the cartridge and install Python 2.6
Please log in to your openshift account and check whether your application and cartridges are up and running.
From the mod_wsgi FAQ:
Q: Why am I seeing the error message 'premature end of script headers'
in the Apache error logs.
A: If using daemon mode, this is a symptom of the mod_wsgi daemon
process crashing when handling a request. You would probably also see
the message 'segmentation fault'. See answer for question about
'segmentation fault' above.
This error message can also occur where you haven't configured Apache
correctly and your WSGI script file is being executed as a CGI script
instead.
It could also be possibly due to the application code hanging. This can be due to the use of third party Python modules which have a C extension component which does not work in Python sub interpreters.
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
Unfortunately OpenShift has a less than ideal mod_wsgi configuration and no ready ability to override the configuration nor the start up of Apache itself. At least not unless that have made significant changes since the last time I looked.

How can I change this Django Application

I was tasked with making some changes to a Django application. I've never worked with Django and I am having trouble figuring out how to get my changes to compile and be available online.
What I know so far is that the application is currently available online. netstat tells me that httpd is listening on port 80. My change was made in the myapp/views.py file.
I tried to restart httpd using services httpd restart but my changes did not take effect. I've been looking into the issue a bit an I believe that I need to run a command along the lines of:
I tried calling python manage.py runserver MY.IP.AD.DR:8000 and I get:
python manage.py runserver 129.64.101.14:8000
Validating models...
0 errors found
Django version 1.4.1, using settings 'cutsheets.settings'
Development server is running at http://MY.IP.AD.DR:8000/
Quit the server with CONTROL-C.
Nice that no errors are found but when I navigate to http://MY.IP.AD.DR:8000/ I just get a "Unable to connect" message from my browser. I tried with port 81 too and had the same problem.
Without knowing exactly how your application is set up, I can't really say exactly how to solve this problem.
I can tell you that it's quite common to use two web servers with Django - one handles the static content, and reverse proxies everything else to a different port where the Django app is listening. Restarting the normal HTTP daemon therefore wouldn't affect the Django app, so you need to restart the one handling the Django app. Until you restart it, the prior version of the code will be running.
I generally use Nginx as my static server and Gunicorn with the Django app, with Supervisor used to run Gunicorn, and this is a common setup. I recommend you take a look at the config for the main web server to see if it forwards anything to another port. If so, you need to see what server is running on that port and restart it.
Also, is there a Fabric configuration (fabfile.py)? A lot of people use Fabric to automate Django deployments, and if there is one then there may be a command already defined for deploying.

Django Ldap authentication timed out

I am hosting a django-based site on a local machine (I have full access/control to it).
This site authenticates users against a remote active directory via the django ldap plugin.
authenticating against LDAP server used to work!
Now, when trying to authenticate against the LDAP server, the request just hangs until it times out. I couldn’t find anything useful in the logs.
The server setup is:
NginX, Django 1.3, Fedora 15, mySql 5.1.
I don’t know what logs I should try to look at.
(I've tried looking in nginx access and error logs but to no use.)
Things I tried:
Running the site on django's and accessing it via localhost (not going through Nginx, but accessing python manage.py directly, via the runserver command). this works
Running ldapsearch from the command line. this works
edit:
i used wireshark to look at the back-and-forth with the ldap server. the interaction seems to be fine - django sends a request to bind and it receives a success msg, and then sends a search query and a user object is returned. however, after this communication django seems to hang. when i "Ctrl-c" in the django shell after running "authenticate(username=user, password=pass)", the stack trace is sitting somewhere in the django-ldap library.
Please help, I have no idea what changed that caused this problem.
Thank you in advance
Active Directory does not allow anonymous binds for authorization; you can bind anonymously but you cannot do anything else.
Check if the user that is being used to bind with AD has valid credentials (ie, the account hasn't expired). If it has, you'll get these strange errors.

apache server with mod_wsgi + python as backend, how can i be able to notified my connection status?

i'm trying to build a web server using apache as the http server, mod_wsgi + python as the logic handler, the server was supposed to handler long request without returning, meaning i want to keep writing stuff into this request.
the problem is, when the link is broken, the socket is in a CLOSE_WAIT status, apache will NOT notify my python program, which means, i have to write something to get an exception, says the link is broken, but those messages were lost and can't be restored.
i tried to get the socket status before writing through /proc/net/tcp, but it could not prevent a quick connect/break connection.
anybody has any ideas, please help, very much thanks in advance!
You cant. It is a limitation of the API defined by the WSGI specification. So, nothing to do with Apache or mod_wsgi really as you will have the same issue with any WSGI server if you follow the WSGI specification.
If you search through the mod_wsgi mailing list on Google Groups you will find a number of discussions about this sort of problem in the past.

Categories