ConnectionRefusedError: [Errno 111] Connection refused

Hello,

I’m using PyODM library for creating orthophotos,

for that I have created flask application.
in wich my function looks like this:-

@app.route('/get-drone', methods =['POST'])
def my_function(user_id):
         all_images_path = "path_of_image/{}/*".format(user_id)
         images = glob.glob(all_images_path)
         task = node.create_task(images, {'dsm': True, 'orthophoto-resolution': 4})
        task.wait_for_completion()
        logger.info("Task completed, downloading results...")
        time.sleep(5)
        # Retrieve results
        task.download_assets("./dron_assests_dsm/{}".format(user_id))

        return "Done"

To test these we you need to start a NodeODM node via:
docker run -ti -p 3000:3000 opendronemap/nodeodm

now I want to run my application using docker-compose file. so for that I have created a docker-compose file, which looks like this:-

version: '3'

services:
      nodeODM:
          image: opendronemap/nodeodm
          ports:
             - '3000:3000'

after doing this docker build is created sucessfully and my application is also up, But when I’m sending request it throw this ConnectionRefusedError:-

File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connection.py”, line 174, in _new_conn
conn = connection.create_connection(
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/util/connection.py”, line 96, in create_connection
raise err
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/util/connection.py”, line 86, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py”, line 699, in urlopen
httplib_response = self._make_request(
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py”, line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connection.py”, line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File “/root/miniconda3/lib/python3.9/http/client.py”, line 1279, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/root/miniconda3/lib/python3.9/http/client.py”, line 1325, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “/root/miniconda3/lib/python3.9/http/client.py”, line 1274, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “/root/miniconda3/lib/python3.9/http/client.py”, line 1034, in _send_output
self.send(msg)
File “/root/miniconda3/lib/python3.9/http/client.py”, line 974, in send
self.connect()
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connection.py”, line 205, in connect
conn = self._new_conn()
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connection.py”, line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f032e7aa5b0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/root/miniconda3/lib/python3.9/site-packages/requests/adapters.py”, line 440, in send
resp = conn.urlopen(
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py”, line 755, in urlopen
retries = retries.increment(
File “/root/miniconda3/lib/python3.9/site-packages/urllib3/util/retry.py”, line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘localhost’, port=3000): Max retries exceeded with url: /info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f032e7aa5b0>: Failed to establish a new connection: [Errno 111] Connection refused’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/root/miniconda3/lib/python3.9/site-packages/pyodm/api.py”, line 128, in get
res = requests.get(self.url(url, query), timeout=self.timeout, **kwargs)
File “/root/miniconda3/lib/python3.9/site-packages/requests/api.py”, line 75, in get
return request(‘get’, url, params=params, **kwargs)
File “/root/miniconda3/lib/python3.9/site-packages/requests/api.py”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “/root/miniconda3/lib/python3.9/site-packages/requests/sessions.py”, line 529, in request
resp = self.send(prep, **send_kwargs)
File “/root/miniconda3/lib/python3.9/site-packages/requests/sessions.py”, line 645, in send
r = adapter.send(request, **kwargs)
File “/root/miniconda3/lib/python3.9/site-packages/requests/adapters.py”, line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘localhost’, port=3000): Max retries exceeded with url: /info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f032e7aa5b0>: Failed to establish a new connection: [Errno 111] Connection refused’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/root/miniconda3/lib/python3.9/site-packages/flask/app.py”, line 2095, in call
return self.wsgi_app(environ, start_response)
File “/root/miniconda3/lib/python3.9/site-packages/flask/app.py”, line 2080, in wsgi_app
response = self.handle_exception(e)
File “/root/miniconda3/lib/python3.9/site-packages/flask/app.py”, line 2077, in wsgi_app
response = self.full_dispatch_request()
File “/root/miniconda3/lib/python3.9/site-packages/flask/app.py”, line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/root/miniconda3/lib/python3.9/site-packages/flask/app.py”, line 1523, in full_dispatch_request
rv = self.dispatch_request()
File “/root/miniconda3/lib/python3.9/site-packages/flask/app.py”, line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File “/api/app.py”, line 1204, in get_dron_call
threading.Thread(target=dron(userFieldId, uploadedDate)).start()
File “/api/app.py”, line 848, in dron
task = node.create_task(images,
File “/root/miniconda3/lib/python3.9/site-packages/pyodm/api.py”, line 246, in create_task
if not self.version_greater_or_equal_than(“1.4.0”):
File “/root/miniconda3/lib/python3.9/site-packages/pyodm/api.py”, line 211, in version_greater_or_equal_than
node_version = self.info().version
File “/root/miniconda3/lib/python3.9/site-packages/pyodm/api.py”, line 180, in info
return NodeInfo(self.get(’/info’))
File “/root/miniconda3/lib/python3.9/site-packages/pyodm/api.py”, line 144, in get
raise NodeConnectionError(str(e))
pyodm.exceptions.NodeConnectionError: HTTPConnectionPool(host=‘localhost’, port=3000): Max retries exceeded with url: /info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f032e7aa5b0>: Failed to establish a new connection: [Errno 111] Connection refused’))

I’m very new in this domain, Please help me in this.

1 Like

when I’m running my application without Docker then it is running fine. But when I’m running my application with docker then only it is throwing the above error.

1 Like

The single hardest part of working with containers is networking.

If your flask app is on a container that’s in the same compose configuration as the nodeodm container, you should be able to reach the nodeodm container if you set things up right.

Networking with standalone containers | Docker Documentation should help, if you haven’t seen it yet.

Good luck!

1 Like

Hi @mathuin

yes my flask app and nodeodm are in same compose file, then also I’m not able to send request to the nodeodm server.

1 Like

I just noticed that you’re attempting to reach localhost:3000 from the flask app – but the nodeodm container isn’t on localhost, it has another name. The page I linked gives examples on user-defined networks and how to be able to reach containers by name. Were it me, I’d name the nodeodm container nodeodm and the flask container flask while inside the same network.

You may have to log into the flask container and use tools like dig and ping to figure things out. Like I said, it’s the hardest part. :frowning:

2 Likes

Thanks @mathuin

The link which you provided, help me a lot. After reading this documentation I have change my docker-compse file and Flask app.py file (from where I’m calling nodeodm module). That looks like this now:-

docker-compose.yml file

version: '3'

services:
      nodeODM:
          image: opendronemap/nodeodm
          container_name: opendronemap-nodeodm
          ports:
             - '3000:3000'

and my app.py file

@app.route('/get-drone', methods =['POST'])
def my_function(user_id):
         all_images_path = "path_of_image/{}/*".format(user_id)
         images = glob.glob(all_images_path)
         node = Node("opendronemap-nodeodm", 3000)
         task = node.create_task(images, {'dsm': True, 'orthophoto-resolution': 4})
         task.wait_for_completion()
         logger.info("Task completed, downloading results...")
         time.sleep(5)
         # Retrieve results
         task.download_assets("./dron_assests_dsm/{}".format(user_id))

         return "Done"

and it works fine.
But now I observe that now for processing the data it is taking way longer then the previous one (when I was not using docker). Can you suggest me waht can I do changes so that it can take less time. and also I don’t all the files which are generated by that module. I only need odm_orthophoto.tif file and image.json file, so there any way to get only this two file.

Thanks

1 Like

I am glad my suggestions helped! I have no magic wand for performance improvements, though. You were probably able to allocate more CPU and RAM in Docker than your standalone system uses. I’m pretty sure images.json is generated early on, so you can probably end processing after the orthophoto stage to save time and resources. Good luck!

1 Like