These two lines don't need to be inside the try / except block ... It is a good practice to keep try blocks minimal to the actual code that can raise the excepts.