Catch exception if open() fails as well.

Drop support for python 2.4.
Merge pull request #2244 from lamblin/fix_setup_readonly

Catch exception if open() fails as well.