I’m trying out deploying a new ML code for a course I’m doing. I’m deploying the model via flask/gunicorn through a docker to test locally.
The docker run (docker run -it --platform linux/amd64 --rm homework_test
) seems to work well.
[2024-06-16 10:04:10 +0000] [1] [INFO] Starting gunicorn 22.0.0
[2024-06-16 10:04:10 +0000] [1] [INFO] Listening at: http://0.0.0.0:9696 (1)
[2024-06-16 10:04:10 +0000] [1] [INFO] Using worker: sync
[2024-06-16 10:04:10 +0000] [8] [INFO] Booting worker with pid: 8
But when I run the Test.py
function on a separate terminal it “times out” (not sure if that is the correct terminology?). I’ve included the full error message below as I’m not sure which steps I should take to debug this.
I’ve already checked that the ports match so that cant be the issue. However, I will include the dockerfile, predict, and test files in the comments too just in case.
(base) marcusleiwe@Marcuss-iMac homework % python test.py
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connection.py", line 203, in _new_conn
sock = connection.create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/util/connection.py", line 85, in create_connection
raise err
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connectionpool.py", line 791, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connectionpool.py", line 497, in _make_request
conn.request(
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connection.py", line 395, in request
self.endheaders()
File "/opt/anaconda3/lib/python3.11/http/client.py", line 1289, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/anaconda3/lib/python3.11/http/client.py", line 1048, in _send_output
self.send(msg)
File "/opt/anaconda3/lib/python3.11/http/client.py", line 986, in send
self.connect()
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connection.py", line 243, in connect
self.sock = self._new_conn()
^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connection.py", line 218, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x10fb438d0>: Failed to establish a new connection: [Errno 61] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/connectionpool.py", line 845, in urlopen
retries = retries.increment(
^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9696): Max retries exceeded with url: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10fb438d0>: Failed to establish a new connection: [Errno 61] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/marcusleiwe/Documents/GitHubRepos/mlops-zoomcamp/cohorts/2024/04-deployment/homework/test.py", line 9, in <module>
requests.post(url, json=year_month)
File "/opt/anaconda3/lib/python3.11/site-packages/requests/api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.11/site-packages/requests/adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9696): Max retries exceeded with url: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10fb438d0>: Failed to establish a new connection: [Errno 61] Connection refused'))