Error in atexit._run_exitfuncs:

I'm not sure why you say that "it is a bug on the code". If you search the forums here,it's only happened once before - No IDN but UnicodeEncodeError - and that was an invalid character.

What should the code do when it receives invalid data ? I guess it could give a more detailed error message that the data is invalid, but it can't just continue.

Without the detail of exactly what you did to create the error it's almost impossible to "solve the problem in the code"

Others may be able to offer something, but personally without an exact copy of what you did I can't really help more.