【python】encode_chunked=req.has_header(‘Transfer-encoding‘))解决方法

在学习使用Keras进行MNIST数据集分类时,遇到Transfer-encoding报错。问题描述及两种解决方法:在py文件中添加特定代码或检查网络状况。参考了相关教程和视频。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

〇、前情提要

在b站跟着up主 天理难容hhhhh 学用keras分类mnist数据集,在第一步认识mnist数据集时,出现了encode_chunked=req.has_header('Transfer-encoding'))报错。
参考:

  1. 手把手用keras分类mnist数据集
    https://blog.youkuaiyun.com/qq_40438165/article/details/105846692
  2. 手把手完成mnist手写数字识别
    https://www.bilibili.com/video/BV16g4y1z7Qu?t=1536

一、问题描述

在这里插入图片描述

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", li
Arguments: datasets_root: None models_dir: saved_models cpu: False seed: None Exception in thread Thread-2: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1350, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1281, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1327, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1276, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1036, in _send_output self.send(msg) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 976, in send self.connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1443, in connect super().connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 948, in connect (self.host,self.port), self.timeout, self.source_address) File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 728, in create_connection raise err File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 30, in download urllib.request.urlretrieve(url, filename=target, reporthook=t.update_to) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1393, in https_open context=self._context, check_hostname=self._check_hostname) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1352, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable> Exception in thread Thread-1: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1350, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1281, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1327, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1276, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1036, in _send_output self.send(msg) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 976, in send self.connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1443, in connect super().connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 948, in connect (self.host,self.port), self.timeout, self.source_address) File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 728, in create_connection raise err File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 30, in download urllib.request.urlretrieve(url, filename=target, reporthook=t.update_to) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1393, in https_open context=self._context, check_hostname=self._check_hostname) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1352, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable> Exception in thread Thread-4: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1350, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1281, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1327, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1276, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1036, in _send_output self.send(msg) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 976, in send self.connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1443, in connect super().connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 948, in connect (self.host,self.port), self.timeout, self.source_address) File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 728, in create_connection raise err File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 30, in download urllib.request.urlretrieve(url, filename=target, reporthook=t.update_to) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1393, in https_open context=self._context, check_hostname=self._check_hostname) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1352, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable> Traceback (most recent call last): File "demo_toolbox.py", line 34, in <module> ensure_default_models(args.models_dir) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 55, in ensure_default_models f"Download for {target_path.name} failed. You may download models manually instead.\n" \ AssertionError: Download for encoder.pt failed. You may download models manually instead. https://drive.google.com/drive/folders/1fU6umc5uQAVR2udZdHX-lDgXYzTyqG_j
最新发布
07-21
Traceback (most recent call last): File "E:\pycharm\PythonProject\京东爬虫6-4.py", line 7, in <module> response = urllib.request.urlopen(url) File "E:\python\Lib\urllib\request.py", line 189, in urlopen return opener.open(url, data, timeout) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "E:\python\Lib\urllib\request.py", line 489, in open response = self._open(req, data) File "E:\python\Lib\urllib\request.py", line 506, in _open result = self._call_chain(self.handle_open, protocol, protocol + '_open', req) File "E:\python\Lib\urllib\request.py", line 466, in _call_chain result = func(*args) File "E:\python\Lib\urllib\request.py", line 1367, in https_open return self.do_open(http.client.HTTPSConnection, req, ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ context=self._context) ^^^^^^^^^^^^^^^^^^^^^^ File "E:\python\Lib\urllib\request.py", line 1319, in do_open h.request(req.get_method(), req.selector, req.data, headers, ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ encode_chunked=req.has_header('Transfer-encoding')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\python\Lib\http\client.py", line 1338, in request self._send_request(method, url, body, headers, encode_chunked) ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\python\Lib\http\client.py", line 1349, in _send_request self.putrequest(method, url, **skips) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^ File "E:\python\Lib\http\client.py", line 1187, in putrequest self._output(self._encode_request(request)) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "E:\python\Lib\http\client.py", line 1267, in _encode_request return request.encode('ascii') ~~~~~~~~~~~~~~^^^^^^^^^ UnicodeEncodeError: 'ascii' codec can't encode characters in position 51-53: ordinal not in range(128)
06-07
C:\Users\Administrator>python -m pip install --user pygame Collecting pygame Using cached pygame-2.6.1.tar.gz (14.8 MB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [108 lines of output] Skipping Cython compilation WARNING, No "Setup" File Exists, Running "buildconfig/config.py" Using WINDOWS configuration... Traceback (most recent call last): File "D:\敲代码学习\Lib\urllib\request.py", line 1319, in do_open h.request(req.get_method(), req.selector, req.data, headers, ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ encode_chunked=req.has_header('Transfer-encoding')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\敲代码学习\Lib\http\client.py", line 1336, in request self._send_request(method, url, body, headers, encode_chunked) ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\敲代码学习\Lib\http\client.py", line 1382, in _send_request self.endheaders(body, encode_chunked=encode_chunked) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\敲代码学习\Lib\http\client.py", line 1331, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\敲代码学习\Lib\http\client.py", line 1091, in _send_output self.send(msg) ~~~~~~~~~^^^^^ File "D:\敲代码学习\Lib\http\client.py", line 1035, in send self.connect() ~~~~~~~~~~~~^^ File "D:\敲代码学习\Lib\http\client.py", line 1470, in connect super().connect() ~~~~~~~~~~~~~~~^^ File "D:\敲代码学习\Lib\http\client.py", line 1001, in connect self.sock = self._create_connection( ~~~~~~~~~~~~~~~~~~~~~~~^
06-01
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值