The behavior is slightly different between Python 2 and 3 so this will have to go in a try block as well.