2

I was trying out this article.

It seems that while making prediction, keras fails to download json because of corporate proxy at line:

results = imagenet_utils.decode_predictions(preds)

The error is as follows:

Using TensorFlow backend.
* Loading Keras model and Flask starting server...please wait until server has fully started
2018-11-21 17:47:27.664222: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
 * Serving Flask app "run_keras_server" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Downloading data from https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json
[2018-11-21 19:04:25,054] ERROR in app: Exception on /predict [POST]
Traceback (most recent call last):
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 1026, in _send_output
    self.send(msg)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 964, in send
    self.connect()
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 1392, in connect
    super().connect()
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\http\client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\socket.py", line 724, in create_connection
    raise err
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\socket.py", line 713, in create_connection
    sock.connect(sa)
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:

Traceback (most recent call last):
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\keras\utils\data_utils.py", line 222, in get_file
    urlretrieve(origin, fpath, dl_progress)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 248, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 544, in _open
    '_open', req)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\urllib\request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.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:

Traceback (most recent call last):
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\flask\app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "D:\Mahesh\workspaces\ignioworkspace6\keras_flask\run_keras_server.py", line 64, in predict
    results = imagenet_utils.decode_predictions(preds)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\keras\applications\__init__.py", line 28, in wrapper
    return base_fun(*args, **kwargs)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\keras\applications\imagenet_utils.py", line 14, in decode_predictions
    *args, **kwargs)
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\keras_applications\imagenet_utils.py", line 228, in decode_predictions
    file_hash='c2c37ea517e94d9795004a39431a14cb')
  File "D:\user123\Programs\python\python-3.6.6-amd64\lib\site-packages\keras\utils\data_utils.py", line 226, in get_file
    raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json: 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
127.0.0.1 - - [21/Nov/2018 19:04:25] "[1m[35mPOST /predict HTTP/1.1[0m" 500 -

How can I set proxy for keras to let it download the desired file? Is there anyway I can manually download this file and make keras use it from filesystem location. Similar error occurred while downloading resnet50_weights_tf_dim_ordering_tf_kernels.h5. So, I manually downloaded it and specified it in the ResNet50().

anir
  • 1,589
  • 9
  • 26

1 Answers1

2

On Windows the Python interpreter will get a proxy from your system environmental variables:

set the system variable HTTP_PROXY to the value http://yourproxy

and the system variable HTTPS_PROXY to the value http://yourproxy

Alternately, you can set the environment in a specific Python terminal session according to the answer to this post set proxy in python session

J.E.Tkaczyk
  • 429
  • 5
  • 17