Cannot save email domain

Unable to save my email domain on a particular ERPNext instance. Throws the following error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_domain/email_domain.py", line 62, in validate
    sess = smtplib.SMTP(cstr(self.smtp_server or ""), cint(self.smtp_port) or None)
  File "/usr/lib64/python3.6/smtplib.py", line 261, in __init__
    fqdn = socket.getfqdn()
  File "/usr/lib64/python3.6/socket.py", line 673, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)

The same domain gets saved on another server without any issue.
Please guide.

My server’s hostname exceeded 64 characters. And hence it kept failing.
More on the issue here: Issue 32958: socket module calls with long host names can fail with idna codec error - Python tracker

I changed the hostname of the server to a smaller string and it worked fine.