It would be better to keep the network handling in the get_prediction method. Move the try logic around urlopen in get_predictions. This will insulate downstream processes from potential errors.