python: retry correctly on name resolution error