# Solution exception:URLError

**URL:** <https://forum.compas-framework.org/t/solution-exception-urlerror/978>\
**Category:** compas\_rhino\
**Created:** [February 3, 2025, 7:17pm UTC](https://forum.compas-framework.org/t/solution-exception-urlerror/978 "2025-02-03T19:17:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dorian123](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/dorian123/32/664_2.png) [@Dorian123](https://forum.compas-framework.org/u/Dorian123)\
**Post date:** [February 3, 2025, 7:17pm UTC](https://forum.compas-framework.org/t/solution-exception-urlerror/978/1 "2025-02-03T19:17:26Z")

</div>

![1](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/0d6f78acfdb06c536da7c12d92475d6471d29762.png)

Hello!  
I am trying to use compas and ARA Machine Learning Plugin by  
Gramazio Kohler Research Lab at ETH for Grasshopper.  
I encountered this problem. Did I missed something in the installation or on the grasshopper canvas or why cant I connect to the server. Or is it simply not existing anymore?

The Error is: 1. Solution exception:URLError  
The URL is: [http://127.0.0.1:8765/shutdown](http://127.0.0.1:8765/shutdown)

Heres also the code of the “Server” Component.

from **future** import absolute\_import  
from **future** import division  
from **future** import print\_function

import urllib2

import compas  
import compas.\_os  
from ghpythonlib.componentbase import executingcomponent as component  
from scriptcontext import sticky as st

from aixd\_ara.constants import DEFAULT\_PORT

try:  
from subprocess import PIPE  
from subprocess import Popen  
except ImportError:  
from System.Diagnostics import Process

import os

import aixd\_ara as ag

class ApiRunner(object):  
def **init** (  
self,  
package=None,  
python=None,  
url=“[http://127.0.0.1](http://127.0.0.1)”,  
port=DEFAULT\_PORT,  
service=None,  
max\_conn\_attempts=100,  
autoreload=True,  
show\_window=False,  
path=None,  
working\_directory=None,  
):  
self.python = compas.\_os.select\_python(python)  
self.service = “aixd\_ara.api”  
self.working\_directory = working\_directory  
self.show\_window = show\_window  
self.port = port

```
    self.start_process()

def start_process(self):
    env = compas._os.prepare_environment()

    try:
        Popen
    except NameError:
        self._process = Process()
        for name in env:
            if self._process.StartInfo.EnvironmentVariables.ContainsKey(name):
                self._process.StartInfo.EnvironmentVariables[name] = env[name]
            else:
                self._process.StartInfo.EnvironmentVariables.Add(name, env[name])
        self._process.StartInfo.UseShellExecute = True
        self._process.StartInfo.RedirectStandardOutput = not self.show_window
        self._process.StartInfo.RedirectStandardError = not self.show_window
        self._process.StartInfo.FileName = self.python
        self._process.StartInfo.Arguments = "-m {0} {1}".format(self.service, self.port)
        self._process.Start()
    else:
        args = [self.python, "-m", self.service, str(self.port)]
        kwargs = dict(env=env)

        if self.show_window:
            if compas.is_mono():
                python_command = " ".join(args)
                apple_script = """
                tell application "Terminal"
                    do script "{}"
                    activate
                end tell
                """.format(
                    python_command
                )
                args = ["osascript", "-e", apple_script]
        else:
            kwargs["stdout"] = PIPE
            kwargs["stderr"] = PIPE

        if self.working_directory:
            kwargs["cwd"] = self.working_directory
        self._process = Popen(args, **kwargs)

def stop_process(self):
    """Attempts to terminate the python process hosting the proxy server.

    The process reference might not be present, e.g. in the case
    of reusing an existing connection. In that case, this is a no-op.
    """
    print("Stopping the server process.")

    if not self._process:
        return

    try:
        self._process.terminate()
    except Exception:
        pass
    try:
        self._process.kill()
    except Exception:
        pass

```

api\_path = os.path.dirname(ag. **file** )

print(api\_path)

def create\_api\_runner\_id(component):  
name = “api-runner”  
return “{}\_{}”.format(name, component.InstanceGuid)

class ApiRunnerComponent(component):

```
def RunScript(self, start, stop, show_window=True):
    key = create_api_runner_id(self)
    port = DEFAULT_PORT

    if show_window:
        python = "python"
    else:
        python = "pythonw"

    if start:
        self.stop(key)
        runner = ApiRunner(python=python, port=port, show_window=show_window, working_directory=api_path)
        st[key] = runner

    if stop:
        self.stop(key)

def stop(self, key):
    # Attempt gracefully stopping the server
    try:
        urllib2.urlopen("http://127.0.0.1:8765/shutdown", timeout=1)
    except Exception:
        pass

    # stop previous API runner if any
    previous_api_runner = st.get(key)
    if previous_api_runner:
        try:
            previous_api_runner.stop_process()
        except Exception as e:
            print("Unable to stop previous process")
            print(e)
        st.pop(key)
    else:
        print("No previous process runner found")

```

---

<div class="post-metadata">

**Author:** ![chenkasirer](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/chenkasirer/32/549_2.png) [@chenkasirer](https://forum.compas-framework.org/u/chenkasirer)\
**Post date:** [February 6, 2025, 12:41pm UTC](https://forum.compas-framework.org/t/solution-exception-urlerror/978/2 "2025-02-06T12:41:35Z")

</div>

Hi Dorian,

Which Rhino version are you using?  
Could you maybe provide the full stack trace for the error? (should be printed below when you open and run the failed component).

Also, did it ever work? is this what you’re seeing immediately after the installation?

Thanks,  
Chen

---

<div class="post-metadata">

**Author:** ![Dorian123](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/dorian123/32/664_2.png) [@Dorian123](https://forum.compas-framework.org/u/Dorian123)\
**Post date:** [February 6, 2025, 1:06pm UTC](https://forum.compas-framework.org/t/solution-exception-urlerror/978/3 "2025-02-06T13:06:29Z")

</div>

Hey!  
Thanks for the reply. It started working out of sudden after trying it a few times 🤷🏼‍♂️.  
So no problems anymore, thanks.
