Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python IDNA标签为空或太长_Python_Url_Download_Python Requests_Urllib - Fatal编程技术网

Python IDNA标签为空或太长

Python IDNA标签为空或太长,python,url,download,python-requests,urllib,Python,Url,Download,Python Requests,Urllib,我正在尝试运行一个在线课程的脚本,并且必须将源代码从Python2语法更改为Python3语法。在这个脚本中,下载了一个归档文件,我已经将其转换为: url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz" urllib.request.urlretrieve(url, filename="../enron_mail_20150507.tgz") 但是,URL似乎有问题,因为它给了我以下错误: Traceback (most

我正在尝试运行一个在线课程的脚本,并且必须将源代码从Python2语法更改为Python3语法。在这个脚本中,下载了一个归档文件,我已经将其转换为:

url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
urllib.request.urlretrieve(url, filename="../enron_mail_20150507.tgz")
但是,URL似乎有问题,因为它给了我以下错误:

Traceback (most recent call last):
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/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 "ud120_code_py35fork/tools/startup.py", line 37, in <module>
    data = urllib.request.urlretrieve("http://...")
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 187, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 465, in open
    response = self._open(req, data)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 483, in _open
    '_open', req)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 443, in _call_chain
    result = func(*args)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 1268, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 1240, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 1083, in request
    self._send_request(method, url, body, headers)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 1079, in endheaders
    self._send_output(message_body)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 911, in _send_output
    self.send(msg)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 854, in send
    self.connect()
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 826, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
回溯(最近一次呼叫最后一次):
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/encodings/idna.py”,第165行,在encode中
raise UnicodeError(“标签为空或太长”)
UnicodeError:标签为空或太长
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“ud120_code_py35fork/tools/startup.py”,第37行,在
data=urllib.request.urlretrieve(“http://...")
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py”,urlretrieve中第187行
使用contextlib.closing(urlopen(url,data))作为fp:
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py”,urlopen第162行
返回opener.open(url、数据、超时)
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py”,第465行,打开
响应=自身打开(请求,数据)
文件“/home/xiaolong/development/Python/udacity\u machine\u learning/localpython/lib/python3.5/urllib/request.py”,第483行,打开
"开放",
文件“/home/xiaolong/development/Python/udacity\u机器学习简介/localpython/lib/python3.5/urllib/request.py”,第443行,在调用链中
结果=func(*args)
文件“/home/xiaolong/development/Python/udacity\u机器学习介绍/localpython/lib/python3.5/urllib/request.py”,第1268行,http\u open
返回self.do_open(http.client.HTTPConnection,req)
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py”,第1240行,在do_open中
h、 请求(请求获取方法(),请求选择器,请求数据,标题)
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py”,请求中的第1083行
self.\u发送请求(方法、url、正文、标题)
文件“/home/xiaolong/development/Python/udacity\u机器学习介绍/localpython/lib/python3.5/http/client.py”,第1128行,在发送请求中
self.endheaders(主体)
文件“/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py”,第1079行,在endheaders中
自发送输出(消息体)
文件“/home/xiaolong/development/Python/udacity\u机器学习简介/localpython/lib/python3.5/http/client.py”,第911行,在发送输出中
self.send(msg)
文件“/home/xiaolong/development/Python/udacity\u机器学习介绍/localpython/lib/python3.5/http/client.py”,第854行,在send中
self.connect()
文件“/home/xiaolong/development/Python/udacity\u intro\u to\u machine\u learning/localpython/lib/python3.5/http/client.py”,第826行,在connect中
(self.host、self.port)、self.timeout、self.source\u地址)
文件“/home/xiaolong/development/Python/udacity\u机器学习介绍/localpython/lib/python3.5/socket.py”,第693行,在create\u connection中
对于getaddrinfo(主机、端口、0、SOCK_流)中的res:
文件“/home/xiaolong/development/Python/udacity\u机器学习介绍/localpython/lib/python3.5/socket.py”,第732行,在getaddrinfo中
对于_socket.getaddrinfo(主机、端口、系列、类型、协议、标志)中的res:
UnicodeError:使用“idna”编解码器编码失败(UnicodeError:标签为空或太长)
我已经试着用
%7E
%2E
替换URL中的
~
,但这根本没有帮助

URL有什么问题,如何修复

  • 确切的python版本:3.5.1

我使用3.5.0和3.4.3时,代码运行得非常好,您使用的是什么版本的python3?@Padraiccningham 3.5.1,将其添加到OP中