Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 16: Downloading Shakespeare model: I get exception downloading the shakespeare_model #123

Open
efakinpelu opened this issue Feb 27, 2024 · 2 comments

Comments

@efakinpelu
Copy link

efakinpelu commented Feb 27, 2024

No description provided.

@efakinpelu efakinpelu changed the title Chapter 16: Downloading Shakespeare model: Chapter 16: Downloading Shakespeare model: I get exception downloading the shakespeare_model Feb 27, 2024
@efakinpelu
Copy link
Author

efakinpelu commented Feb 27, 2024

Here's the code as I ran it:

import tensorflow as tf
from pathlib import Path

# extra code – downloads a pretrained model
url = "https://github.com/ageron/data/raw/main/shakespeare_model.tgz"
path = tf.keras.utils.get_file("shakespeare_model.tgz", url, extract=True)
model_path = Path(path).with_name("shakespeare_model")
#shakespeare_model = tf.keras.models.load_model(model_path)

The stack trace I got:

Downloading data from https://github.com/ageron/data/raw/main/shakespeare_model.tgz
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
File ~\anaconda3\envs\bdl\lib\urllib\request.py:1346, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1345 try:
-> 1346     h.request(req.get_method(), req.selector, req.data, headers,
   1347               encode_chunked=req.has_header('Transfer-encoding'))
   1348 except OSError as err: # timeout error

File ~\anaconda3\envs\bdl\lib\http\client.py:1285, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
   1284 """Send a complete request to the server."""
-> 1285 self._send_request(method, url, body, headers, encode_chunked)

File ~\anaconda3\envs\bdl\lib\http\client.py:1331, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
   1330     body = _encode(body, 'body')
-> 1331 self.endheaders(body, encode_chunked=encode_chunked)

File ~\anaconda3\envs\bdl\lib\http\client.py:1280, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1279     raise CannotSendHeader()
-> 1280 self._send_output(message_body, encode_chunked=encode_chunked)

File ~\anaconda3\envs\bdl\lib\http\client.py:1040, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1039 del self._buffer[:]
-> 1040 self.send(msg)
   1042 if message_body is not None:
   1043 
   1044     # create a consistent interface to message_body

File ~\anaconda3\envs\bdl\lib\http\client.py:980, in HTTPConnection.send(self, data)
    979 if self.auto_open:
--> 980     self.connect()
    981 else:

File ~\anaconda3\envs\bdl\lib\http\client.py:1454, in HTTPSConnection.connect(self)
   1452     server_hostname = self.host
-> 1454 self.sock = self._context.wrap_socket(self.sock,
   1455                                       server_hostname=server_hostname)

File ~\anaconda3\envs\bdl\lib\ssl.py:501, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    495 def wrap_socket(self, sock, server_side=False,
    496                 do_handshake_on_connect=True,
    497                 suppress_ragged_eofs=True,
    498                 server_hostname=None, session=None):
    499     # SSLSocket class handles server_hostname encoding before it calls
    500     # ctx._wrap_socket()
--> 501     return self.sslsocket_class._create(
    502         sock=sock,
    503         server_side=server_side,
    504         do_handshake_on_connect=do_handshake_on_connect,
    505         suppress_ragged_eofs=suppress_ragged_eofs,
    506         server_hostname=server_hostname,
    507         context=self,
    508         session=session
    509     )

File ~\anaconda3\envs\bdl\lib\ssl.py:1074, in SSLSocket._create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
   1073             raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
-> 1074         self.do_handshake()
   1075 except (OSError, ValueError):

File ~\anaconda3\envs\bdl\lib\ssl.py:1343, in SSLSocket.do_handshake(self, block)
   1342         self.settimeout(None)
-> 1343     self._sslobj.do_handshake()
   1344 finally:

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
File ~\anaconda3\envs\bdl\lib\site-packages\keras\utils\data_utils.py:296, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    295 try:
--> 296     urlretrieve(origin, fpath, DLProgbar())
    297 except urllib.error.HTTPError as e:

File ~\anaconda3\envs\bdl\lib\site-packages\keras\utils\data_utils.py:84, in urlretrieve(url, filename, reporthook, data)
     82             break
---> 84 response = urlopen(url, data)
     85 with open(filename, "wb") as fd:

File ~\anaconda3\envs\bdl\lib\urllib\request.py:214, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    213     opener = _opener
--> 214 return opener.open(url, data, timeout)

File ~\anaconda3\envs\bdl\lib\urllib\request.py:523, in OpenerDirector.open(self, fullurl, data, timeout)
    522     meth = getattr(processor, meth_name)
--> 523     response = meth(req, response)
    525 return response

File ~\anaconda3\envs\bdl\lib\urllib\request.py:632, in HTTPErrorProcessor.http_response(self, request, response)
    631 if not (200 <= code < 300):
--> 632     response = self.parent.error(
    633         'http', request, response, code, msg, hdrs)
    635 return response

File ~\anaconda3\envs\bdl\lib\urllib\request.py:555, in OpenerDirector.error(self, proto, *args)
    554 args = (dict, proto, meth_name) + args
--> 555 result = self._call_chain(*args)
    556 if result:

File ~\anaconda3\envs\bdl\lib\urllib\request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    493 func = getattr(handler, meth_name)
--> 494 result = func(*args)
    495 if result is not None:

File ~\anaconda3\envs\bdl\lib\urllib\request.py:747, in HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
    745 fp.close()
--> 747 return self.parent.open(new, timeout=req.timeout)

File ~\anaconda3\envs\bdl\lib\urllib\request.py:517, in OpenerDirector.open(self, fullurl, data, timeout)
    516 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 517 response = self._open(req, data)
    519 # post-process response

File ~\anaconda3\envs\bdl\lib\urllib\request.py:534, in OpenerDirector._open(self, req, data)
    533 protocol = req.type
--> 534 result = self._call_chain(self.handle_open, protocol, protocol +
    535                           '_open', req)
    536 if result:

File ~\anaconda3\envs\bdl\lib\urllib\request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    493 func = getattr(handler, meth_name)
--> 494 result = func(*args)
    495 if result is not None:

File ~\anaconda3\envs\bdl\lib\urllib\request.py:1389, in HTTPSHandler.https_open(self, req)
   1388 def https_open(self, req):
-> 1389     return self.do_open(http.client.HTTPSConnection, req,
   1390         context=self._context, check_hostname=self._check_hostname)

File ~\anaconda3\envs\bdl\lib\urllib\request.py:1349, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1348 except OSError as err: # timeout error
-> 1349     raise URLError(err)
   1350 r = h.getresponse()

URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
Cell In[2], line 6
      4 # extra code – downloads a pretrained model
      5 url = "https://github.com/ageron/data/raw/main/shakespeare_model.tgz"
----> 6 path = tf.keras.utils.get_file("shakespeare_model.tgz", url, extract=True)
      7 model_path = Path(path).with_name("shakespeare_model")

File ~\anaconda3\envs\bdl\lib\site-packages\keras\utils\data_utils.py:300, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    298         raise Exception(error_msg.format(origin, e.code, e.msg))
    299     except urllib.error.URLError as e:
--> 300         raise Exception(error_msg.format(origin, e.errno, e.reason))
    301 except (Exception, KeyboardInterrupt):
    302     if os.path.exists(fpath):

Exception: URL fetch failure on https://github.com/ageron/data/raw/main/shakespeare_model.tgz: None -- [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Please what am I doing wrong?

@ageron
Copy link
Owner

ageron commented Jun 4, 2024

Your code looks good to me, in fact I've just tested it and it works fine. This might just be a temporary issue on github, you could just try again and hopefully it will work. If not, then it's probably a network issue: check your router, wifi, firewall, and so on. If nothing works, you can try downloading the file manually, and place it in <your home folder>/.keras/datasets, then run the code again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants