Remove use of deprecated method in Python sample and make easier to test