Friday, 29 April 2011

AWS Signature mismatch with python-boto

With python-boto 1.9b4, connecting to Amazon Cloud services using the following commands

>>>from boto.ec2.connection import EC2Connection
>>>conn = EC2Connection(<your AWS key>, <your secret key>

failed an error message as follows:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/boto/ec2/", line 119, in get_all_images
return self.get_list('DescribeImages', params, [('item', Image)])
File "/usr/lib/python2.7/site-packages/boto/", line 615, in get_list
raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message></Error></Errors><RequestID>kept-out-of-post</RequestID></Response>

The issue disappears when you update to python-boto 2.0b4.

Altering django models

I wanted to add a column to an existing django model; but django does not support modifications to existing models so when I added a line to and ran syncdb, I found no change. The workaround was to manually edit the schema in mysql (or your preferred database backend).

alter table <table name> add column <column name> varchar(512);

Sunday, 24 April 2011

Using CSS files in Django

In Django, cascading style sheets are served as static content. To begin with create the following URL mapping in your

from django.conf import settings

urlpatters = patterns (
   #other patterns
   (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),

In set the following variables.

MEDIA_ROOT = '/home/user/site/static'
STATIC_URL = '/css/'

All css files are put in the css folder and can be referred to in templates as /static/css/filename.css.

Generating public and private keys

Asymmetric keys are often used so I shall describe two ways of generating them. Using openssl we can generate them as follows:

openssl genrsa -out key.priv 1024
openssl rsa -in key.priv -out -pubout

The key pair generated above can be used as follows:
- distribute the public key so that messages can be encrypted using the public key
- use the private key to decrypt them

Whenever there is the need for a password, the ssh format for RSA and DSA keys can be used. An ssh key-pair can be generated in the following way.

ssh-keygen -t rsa -b 2048