首页 > 解决方案 > python3 UnicodeError:使用“idna”编解码器编码失败(UnicodeError:标签为空或太长)

问题描述

我在运行我的程序时遇到了一些问题。我有一个“主文件”,它在 \n 上有一个 ips 列表,就像这样,但我不断收到此错误消息:

68.x.0.56
68.x.0.53

我不确定到底是什么问题,但我一直在搜索论坛和其他 stackoverflow 帮助,但似乎无法确定问题所在。

def dns_resolver(subdomains):
    print('\n\n########## Checking Subdomains for DNS Resolutions ##########\n')
    queries = []
    with open ('masterfile', 'r') as f:
        domains = f.read().splitlines()
        for i in domains:
            try:
                resp = socket.gethostbyname(i)
                print(resp)
                queries.append((i, resp))
            except socket.error:
                pass
    return queries

Traceback (most recent call last):
  File "/usr/lib/python3.6/encodings/idna.py", line 165, in encode
    raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "subdomain-hunter.py", line 170, in <module>
    main()
  File "subdomain-hunter.py", line 59, in main
    enumerate(DOMAIN)
  File "subdomain-hunter.py", line 120, in enumerate
    resolvediff = dns_resolver(diff)
  File "subdomain-hunter.py", line 142, in dns_resolver
    resp = socket.gethostbyname(i)
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)

标签: python-3.xunicode

解决方案


推荐阅读