Posted: February 28th, 2007 | Author: Matt Croydon | Filed under: Linux, Open Source, Projects, Python | 1 Comment »
The other day I was looking in to why Django‘s verify_exists validator wasn’t working on a URLField. It turns out that the 404 handler that we were using to generate thumbnails with lighttpd on the media server was serving up 404 error pages with
HTTP/1.1 200 OK as the status code. Django’s validator was seeing the
200 OK and (rightfully) not raising a validation error, even though there was nothing at that location.
It took more than the usual amount of digging to find the solution to this, so I’m making sure to write about it so that I can google for it again when it happens to me next year. The server.error-hadler-404 documentation metnions that to send a 404 response you will need to use server.errorfile-prefix. That doesn’t help me a lot since I needed to retain the dynamic 404 handler.
Amusingly enough, the solution is quite clear once you dig in to the source code. I dug through connections.c and found that if I sent back a
Status: line, that would be forwarded on by lighttpd to the client (exactly what I wanted!)
Here’s the solution (in Python) but it should translate to any language that you’re using as a 404 handler:
print "Status: 404"
print "Content-type: text/html"
print # (X)HTML error response goes here
I hope this helps, as I’m sure it will help me again some time in the future.
Posted: February 11th, 2007 | Author: Matt Croydon | Filed under: Linux, Open Source, Projects | 6 Comments »
I found myself wanting to do some image manipulation in Python with the Python Imaging Library on my N800. Unfortunately PIL isn’t available in the standard repositories. Not to worry, after reading the Debian Maintainers’ Guide I packaged up python2.5-imaging_1.1.6-1_armel.deb, built against python2.5 and maemo 3.0 (bora), and installs perfectly on my N800:
Nokia-N800-51:/media/mmc1# dpkg -i python2.5-imaging_1.1.6-1_armel.deb
Selecting previously deselected package python2.5-imaging.
(Reading database ... 13815 files and directories currently installed.)
Unpacking python2.5-imaging (from python2.5-imaging_1.1.6-1_armel.deb) ...
Setting up python2.5-imaging (1.1.6-1) ...
Python 2.5 (r25:9277, Jan 23 2007, 15:56:37)
[GCC 3.4.4 (release) (CodeSourcery ARM 2005q3-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
Feel free to take a look at the directory listing for full source, diffs, etc. You might also want to check out
debian/rules to see where to use setup.py in the makefile to build and install a Python package. If anyone wants a build of this for maemo-2.0/770 please let me know. It would just take a little time to set up a maemo-2.0 scratchbox.
Posted: February 4th, 2007 | Author: Matt Croydon | Filed under: Linux, Mobile, Open Source, Python | 43 Comments »
I received my Nokia N800 yesterday and have been enjoying how zippy it is compared to the 770 (which has been getting faster with every firmware upgrade).. I got a chance to play with the browser while waiting for my wife at the airport and have been poking around to see how Bora is different than Mistral and Scirocco.
One of the bigger physical differences between the 770 an N800 is the onboard camera. I haven’t set up Nokia Internet Call Invitation yet but I looked around for some camera code samples and was pleasantly suprised. Luckily Nokia is one step ahead of me with camera.py, an example program to show what the camera sees on the screen. It looks like some bindings are missing so saving an image from the camera is off limits at the moment but this is a great start.
To run the above example on your N800, grab camera.py, install Python and osso-xterm, and run camera.py from the console.
It’s time to dust off the Python Maemo tutorial and get my feet wet.
Update: I’ve also been playing with the c version of the camera example code and have managed to get it running and taking pictures after building it in scratchbox and running it with