Python 3.x 异常:加载数据时URL获取失败
我正在试着把我的机器设置成运行Tensorflow 2。我从未使用过Tensorflow,只是下载了Python 3.7。我不确定这是否是我的机器的问题。我遵循上列出的安装说明。我按照安装说明进行操作,似乎一切正常 MacOS 10.15.3 Python 3.7 张量流2 我创建了一个小程序只是为了测试一下。这就是我所拥有的:Python 3.x 异常:加载数据时URL获取失败,python-3.x,tensorflow,keras,python-3.7,tensorflow2.0,Python 3.x,Tensorflow,Keras,Python 3.7,Tensorflow2.0,我正在试着把我的机器设置成运行Tensorflow 2。我从未使用过Tensorflow,只是下载了Python 3.7。我不确定这是否是我的机器的问题。我遵循上列出的安装说明。我按照安装说明进行操作,似乎一切正常 MacOS 10.15.3 Python 3.7 张量流2 我创建了一个小程序只是为了测试一下。这就是我所拥有的: import io import matplotlib.pyplot as plt import tensorflow as tf from tensorflow im
import io
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
import numpy as np
data = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = data.load_data()
当我运行data.load_data()
时,出现以下错误:
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
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 1244, 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 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 966, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1414, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py", line 263, in get_file
urlretrieve(origin, fpath, dl_progress)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 247, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jacksonmelcher/Development/Personal/TensorFlow/tf_embeddings.py", line 12, in <module>
(train_images, train_labels), (test_images, test_labels) = data.load_data()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/python/keras/datasets/fashion_mnist.py", line 75, in load_data
paths.append(get_file(fname, origin=base + fname, cache_subdir=dirname))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py", line 267, in get_file
raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)
从中下载数据https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
回溯(最近一次呼叫最后一次):
dou open中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第1317行
encode_chunked=req.has_头('Transfer-encoding'))
请求中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第1244行
self.\u发送\u请求(方法、url、正文、标题、编码\u分块)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第1290行,在发送请求中
self.endheaders(body,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第1239行,在endheaders中
self.\u发送\u输出(消息体,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第1026行,在发送输出中
self.send(msg)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第966行,在send中
self.connect()
connect中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第1414行
服务器\主机名=服务器\主机名)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第423行,在wrap_套接字中
会话=会话
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第870行,在创建
self.do_握手
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第1139行,在do_握手中
赛尔夫:握手
ssl.SSLCertVerificationError:[ssl:证书\u验证\u失败]证书验证失败:无法获取本地颁发者证书(\u ssl.c:1076)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/tensorflow/Python/keras/utils/data_utils.py”,get_文件第263行
urlretrieve(源、fpath、dl_进度)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第247行,在urlretrieve中
使用contextlib.closing(urlopen(url,data))作为fp:
urlopen中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第222行
返回opener.open(url、数据、超时)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第525行,打开
响应=自身打开(请求,数据)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第543行,打开
"开放",
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第503行,在调用链中
结果=func(*args)
https_open中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第1360行
上下文=self.\u上下文,检查主机名=self.\u检查主机名)
dou open中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第1319行
引发URL错误(err)
urllib.error.urleror:
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/jacksonmelcher/Development/Personal/TensorFlow/tf_embeddings.py”,第12行,在
(列车图像,列车标签),(测试图像,测试标签)=数据。加载列车数据()
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/tensorflow/Python/keras/datasets/fashion_mnist.py”,第75行,加载数据
append(获取文件(fname,origin=base+fname,cache\u subdir=dirname))
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/tensorflow/Python/keras/utils/data_utils.py”,get_文件第267行
引发异常(错误消息格式(origin,e.errno,e.reason))
异常:上的URL获取失败https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: 无--[SSL:CERTIFICATE\u VERIFY\u FAILED]证书验证失败:无法获取本地颁发者证书(\u SSL.c:1076)
同样,这是我第一次使用Tensorflow和Keras,但它似乎与google的api服务存在连接问题
非常感谢您的帮助,因为我找不到任何东西。您可以尝试使用Chrome访问下载数据集 然后更改代码
(train_images, train_labels), (test_images, test_labels) = data.load_data()
作为
希望能帮到你 您可以尝试使用Chrome访问下载数据集 然后更改代码
(train_images, train_labels), (test_images, test_labels) = data.load_data()
作为
希望能帮到你 同样的代码在我的网络上运行得很好。这可能是您的网络出现问题。我更改了网络,但收到了相同的错误。我可能应该尝试卸载并重新安装python。同样的代码在我的网络上运行得非常好。这可能是您的网络出现问题。我更改了网络,但收到了相同的错误。我可能应该尝试卸载并重新安装python