Exception: URL fetch failure on https://s3.amazonaws.com/text-datasets/nietzsche.txt: None -- [WinError 10054] 遠端主機強迫關閉了一個現有的連線。
阿新 • • 發佈:2021-07-22
原始程式碼:
import keras import numpy as np path = keras.utils.get_file( 'nietzsche.txt', origin='https://s3.amazonaws.com/text-datasets/nietzsche.txt' ) text = open(path).read().lower() print('Corpus length:', len(text))
報錯情況:
D:\Anaconda\envs\tensorflow\python.exe D:/PYCHARMprojects/Dailypractise/p23.py Downloading datafrom https://s3.amazonaws.com/text-datasets/nietzsche.txt Traceback (most recent call last): File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 1354, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "D:\Anaconda\envs\tensorflow\lib\http\client.py", line 1255, inrequest self._send_request(method, url, body, headers, encode_chunked) File "D:\Anaconda\envs\tensorflow\lib\http\client.py", line 1301, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "D:\Anaconda\envs\tensorflow\lib\http\client.py", line 1250, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "D:\Anaconda\envs\tensorflow\lib\http\client.py", line 1010, in _send_output self.send(msg) File "D:\Anaconda\envs\tensorflow\lib\http\client.py", line 950, in send self.connect() File "D:\Anaconda\envs\tensorflow\lib\http\client.py", line 1424, in connect self.sock = self._context.wrap_socket(self.sock, File "D:\Anaconda\envs\tensorflow\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "D:\Anaconda\envs\tensorflow\lib\ssl.py", line 1040, in _create self.do_handshake() File "D:\Anaconda\envs\tensorflow\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() ConnectionResetError: [WinError 10054] 遠端主機強迫關閉了一個現有的連線。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\keras\utils\data_utils.py", line 278, in get_file urlretrieve(origin, fpath, dl_progress) File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 222, in urlopen return opener.open(url, data, timeout) File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 525, in open response = self._open(req, data) File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 542, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 502, in _call_chain result = func(*args) File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 1397, in https_open return self.do_open(http.client.HTTPSConnection, req, File "D:\Anaconda\envs\tensorflow\lib\urllib\request.py", line 1357, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [WinError 10054] 遠端主機強迫關閉了一個現有的連線。> During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:/PYCHARMprojects/Dailypractise/p23.py", line 9, in <module> path = keras.utils.get_file( File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\keras\utils\data_utils.py", line 282, in get_file raise Exception(error_msg.format(origin, e.errno, e.reason)) Exception: URL fetch failure on https://s3.amazonaws.com/text-datasets/nietzsche.txt: None -- [WinError 10054] 遠端主機強迫關閉了一個現有的連線。 Process finished with exit code 1
解決方案:
1、直接在瀏覽器搜尋該網址,右擊將其另存到一個地方。
2、修改程式碼
import keras import numpy as np path = r'D:\PYCHARMprojects\Dailypractise\nietzsche.txt'#檔案儲存地址
text = open(path).read().lower() print('Corpus length:', len(text))
3、執行成功
歡迎關注我的CSDN部落格心繫五道口,有問題請私信[email protected]