while True:
cpf = input('Digite os nove primeiros dígitos do CPF: ')
if len(cpf) == 9:
break
#mais código aqui
#http://pt.stackoverflow.com/q/187587/101
d2hpbGUgVHJ1ZToKICAgIGNwZiA9IGlucHV0KCdEaWdpdGUgb3Mgbm92ZSBwcmltZWlyb3MgZMOtZ2l0b3MgZG8gQ1BGOiAnKQogICAgaWYgbGVuKGNwZikgPT0gOToKICAgICAgICBicmVhawogICAgI21haXMgY8OzZGlnbyBhcXVpCgojaHR0cDovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvMTg3NTg3LzEwMQ==