500 Errors and premature end of script headers [Python, Django]


#1

I’ve been running Python/Django on Dreamhosts’s shared hosting service for quite a while, and apparently sometime this weekend the server is now giving me consistent 500 errors. It’s not giving me my custom 500 error, so it’s apparently puking sometime before it hits my Django framework. In my error logs, there are numerous logs like this:

[Mon Oct 06 07:04:40 2014] [error] [client 173.172.189.216] Premature end of script headers: game, referer: http://www.robandkriskris.com/game/165 [Mon Oct 06 07:04:40 2014] [error] [client 173.172.189.216] Premature end of script headers: internal_error.html, referer: http://www.robandkriskris.com/game/165 [Mon Oct 06 07:04:48 2014] [error] [client 173.172.189.216] Premature end of script headers: [Mon Oct 06 07:04:48 2014] [error] [client 173.172.189.216] Premature end of script headers: internal_error.html [Mon Oct 06 07:05:56 2014] [error] [client 183.60.213.113] Premature end of script headers: game [Mon Oct 06 07:05:56 2014] [error] [client 183.60.213.113] Premature end of script headers: internal_error.html

When I try to redeploy my server (using fab deploy), I get Python installation errors I’ve never gotten before like this:

[code]ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last): [10/400]
File “/home/thesp/robandkriskris.com/env/lib/python2.7/hashlib.py”, line 139, in
globals()[__func_name] = __get_hash(__func_name)
File “/home/thesp/robandkriskris.com/env/lib/python2.7/hashlib.py”, line 91, in __get_builti$
_constructor
raise ValueError('unsupported hash type ’ + name)

ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
File “/home/thesp/robandkriskris.com/env/lib/python2.7/hashlib.py”, line 139, in
globals()[__func_name] = __get_hash(__func_name)
File “/home/thesp/robandkriskris.com/env/lib/python2.7/hashlib.py”, line 91, in __get_builti$_constructor
raise ValueError('unsupported hash type ’ + name)

ValueError: unsupported hash type sha512
Traceback (most recent call last):
File “/home/thesp/robandkriskris.com/env/bin/pip”, line 8, in
load_entry_point(‘pip==1.4.1’, ‘console_scripts’, ‘pip’)()
File “/home/thesp/robandkriskris.com/env/lib/python2.6/site-packages/setuptools-1.1.6 -py2.6.$gg/pkg_resources.py”, line 357, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/home/thesp/robandkriskris.com/env/lib/python2.6/site-packages/setuptools-1.1.6 -py2.6.$gg/pkg_resources.py”, line 2394, in load_entry_point
return ep.load()
File “/home/thesp/robandkriskris.com/env/lib/python2.6/site-packages/setuptools-1.1.6 -py2.6.$gg/pkg_resources.py”, line 2108, in load
entry = import(self.module_name, globals(),globals(), [‘name’])
File “/home/thesp/robandkriskris.com/env/lib/python2.7/site-packages/pip-1.4.1-py2.7. egg/pip$init.py”, line 10, in
from pip.util import get_installed_distributions, get_prog
File “/home/thesp/robandkriskris.com/env/lib/python2.7/site-packages/pip-1.4.1-py2.7. egg/pip$util.py”, line 17, in
from pip.vendor.distlib import version
File “/home/thesp/robandkriskris.com/env/lib/python2.7/site-packages/pip-1.4.1-py2.7. egg/pip$vendor/distlib/version.py”, line 13, in
from .compat import string_types
File “/home/thesp/robandkriskris.com/env/lib/python2.7/site-packages/pip-1.4.1-py2.7. egg/pip/
vendor/distlib/compat.py”, line 31, in
from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler[/code]

Was something upgraded or changed over the weekend to cause these problems? Any advice on how to fix? I imagine I might need to wipe my virtual environment and reinstall, but I’m hesitant to do that if it won’t work (or will make things worse). Any advice is appreciated. Thanks!


#2

I’m having the same issue with my Python, Django site, but don’t have a solution yet either. I’ve learned that many servers were upgraded to Ubuntu 12.04 recently which I suspect is when the problem started. ( http://www.dreamhoststatus.com/2014/09/30/upgrading-150-shared-web-hosting-servers-to-ubuntu-12-04-precise-october-5th-8pm-1am-pdt/ )


#3

Same here, didn’t knew about the problem until some of my costumers complained. Apparently it was an upgrade.

While I really needed this upgrade for my new projects with django 1.7, I wish I had a heads up.

I solved this issue by deleting my virtualenvs and re-creating them (and installing all my modules again). I had a problem with setup_tools also, downloaded from https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py

My steps were:

rm -R <my_site>/env
virtualenv <my_site>/env
source <my_site>/env/bin/activate
mkdir ~/tmp
cd ~/tmp
wget https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py
python ez_setup.py
cd <my_site>/my_project/
pip install -r requirements.txt
touch <my_site>/tmp/restart.txt

On my case, I had my virtualenv en <my_site>/env


#4

Thanks for this wisdom. I imagined I’d need to do something like this. I may have made it worse by trying to reinstall Python along the way as well. :confused:

I’m close, I think, but I’m hitting another weird error I can’t crack. (I’ve been banging my head against the desk for the past three hours on it!) It’s puking with this trace:

Traceback (most recent call last):
  File "/home/thesp/robandkriskris.com/env/lib/python2.7/site-packages/site.py", line 74, in <module>
    __boot()
  File "/home/thesp/robandkriskris.com/env/lib/python2.7/site-packages/site.py", line 2, in __boot
    import sys, os, os.path
  File "/home/thesp/lib/python2.7/os.py", line 400, in <module>
    import UserDict
  File "/home/thesp/lib/python2.7/UserDict.py", line 83, in <module>
    import _abcoll
  File "/home/thesp/lib/python2.7/_abcoll.py", line 11, in <module>
    from abc import ABCMeta, abstractmethod
  File "/home/thesp/lib/python2.7/abc.py", line 8, in <module>
    from _weakrefset import WeakSet
ImportError: No module named _weakrefset

I saw some suggestions that upgrading virtualenv will fix this, but I’ve done that (version 1.11.6) and it’s not helped in the slightest. What seems particularly unusual here is that the first two calls in the trace are pulling from the virtual environment, but the subsequent calls aren’t. Any idea what might cause that, or how to fix it? Thanks so much!
[hr]

Weirder still - I can run “python manage.py runserver” without a problem, and I can (from a Python shell) run “from _weakrefset import WeakSet” without an import error. It still pukes when trying to load from the web, though. Blergh.


#5

I’ve finally fixed the problem. I went to the /home/thesp/lib/python2.7/ directory and downloaded _weakrefset.py, like so:

…and now everything seems to be running fine. There was a _weakrefset.pyo file in the directory, so I’m not sure why _weakrefset.py never made it in, but this seems to have done the trick.

Now, that doesn’t solve the mystery of why the stack trace switches directories like it does, but it’s running now, so I’ll take it for now!