So this is returning None if something fails, but it's not as straight forward as it should IMO. May be you should initialize period to None before the try and then return period outside the else?