Python: check bad url function