Wednesday, November 16, 2011

Another strange Django error

If you stumble across the error in Django 1.3:

  ...
  File "/Users/brad/work/django-formwizard/.env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 368, in reverse
    app_list = resolver.app_dict[ns]
  File "/Users/brad/work/django-formwizard/.env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 241, in _get_app_dict
    self._populate()
  File "/Users/brad/work/django-formwizard/.env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 198, in _populate
    p_pattern = pattern.regex.pattern
AttributeError: 'str' object has no attribute 'regex'


Or in Django 1.4:


...

  File "/brew/Cellar/python/2.7.1/lib/python2.7/site-packages/django/core/handlers/base.py", line 101, in get_response
    request.path_info)
  File "/brew/Cellar/python/2.7.1/lib/python2.7/site-packages/django/core/urlresolvers.py", line 300, in resolve
    sub_match = pattern.resolve(new_path)
AttributeError: 'str' object has no attribute 'resolve'



You have probably accidentally left a trailing comma in the URLCONF_ROOT setting, i.e.:


ROOT_URLCONF = 'project.urls',

Sunday, November 13, 2011

Strange UTF-8 decoding error with Jenkins + Python

I've come across a strange problem while setting up Jenkins to build Python projects. For some reason I get the following error:


Traceback (most recent call last):
  File "setup.py", line 32, in <module>
    'Topic :: Software Development :: Libraries :: Python Modules',
  File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  ...

  File "/home/jenkins/.jenkins/jobs/django-console/workspace/django_attest-0.1.1-py2.7.egg/django_attest/__init__.py", line 0
SyntaxError: 'NoneType' object has no attribute 'utf_8_decode'

In any case it's fixed by adding the following as an environment variable (I added it to the Properties Content section):
LANG=en_AU.UTF-8

Thursday, November 10, 2011

Upstart + Jenkins

I've been playing with Jenkins for CI of Python projects. I run Jenkins on 127.0.0.1:8081, and then use Apache2 to proxy a domain to it. Here's a simple virtual host configuration I found somewhere:


<VirtualHost *:80>
    ServerName jenkins
    ProxyPass         /  http://localhost:8081/
    ProxyPassReverse  /  http://localhost:8081/
    ProxyRequests     Off
    # Local reverse proxy authorization override
    # Most unix distribution deny proxy by default (ie
    # /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
    <Proxy http://localhost:8081*>
      Order deny,allow
      Allow from all
    </Proxy>
</VirtualHost>


Lastly I wrote an Upstart job in /etc/init/jenkins.conf to keep it running across restarts:


description "Jenkins"


respawn
start on started network-services
stop on stopping network-services


script
cd /home/jenkins
sudo -Hu jenkins java -jar jenkins.war -Djava.awt.headless=true --httpPort=8081 --httpListenAddress=127.0.0.1
end script