qarnot / qarnot-sdk-python

Python SDK to use Qarnot's computing service
Apache License 2.0
13 stars 4 forks source link

Advanced hello world example causes urllib3 error #8

Closed calebfaruki closed 3 years ago

calebfaruki commented 3 years ago

https://computing.qarnot.com/en/developers/samples/hello-world

Using tutorial example, loading http configuration and access token from a file fails, resulting in the error below:

Traceback (most recent call last):
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pdb.py", line 1704, in main
    pdb._runscript(mainpyfile)
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pdb.py", line 1573, in _runscript
    self.run(statement)
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/bdb.py", line 580, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "~/myproject/sample1_helloworld.py", line 3, in <module>
    import sys
  File "~/myproject/venv/lib/python3.8/site-packages/qarnot/connection.py", line 168, in __init__
    api_settings = self._get(get_url("settings")).json()
  File "~/myproject/venv/lib/python3.8/site-packages/qarnot/connection.py", line 220, in _get
    ret = self._http.get(self.cluster + url, timeout=self.timeout,
  File "~/myproject/venv/lib/python3.8/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "~/myproject/venv/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "~/myproject/venv/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "~/myproject/venv/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.quarnot.com', port=443): Max retries exceeded with url: /settings (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x102491490>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

To reproduce, follow the sample1_helloworld.py example exactly.

[cluster]
url=https://api.quarnot.com

[client]
token=xxxx-mytoken-xxxx
#!/usr/bin/env python

import sys
import qarnot

# Edit 'samples.conf' to provide your own credentials

# Create a connection, from which all other objects will be derived
conn = qarnot.Connection('samples.conf')

# Create a task. The 'with' statement ensures that the task will be
# deleted in the end, to prevent tasks from continuing to run after
# a Ctrl-C for instance
task = conn.create_task('sample1-helloword-advanced', 'docker-batch', 2)

# Store if an error happened during the process
error_happened = False
try:
    # Set the command to run when launching the container, by overriding a
    # constant.
    # Task constants are the main way of controlling a task's behaviour
    task.constants['DOCKER_CMD'] = 'sh -c "echo Hello world from $QRANK/$QSIZE!"'

    # Submit the task to the Api, that will launch it on the cluster
    task.submit()

    # Wait for the task to be finished, and monitor the progress of its
    # deployment
    last_state = ''
    done = False
    while not done:
        if task.state != last_state:
            last_state = task.state
            print("** {}".format(last_state))

        # Wait for the task to complete, with a timeout of 5 seconds.
        # This will return True as soon as the task is complete, or False
        # after the timeout.
        done = task.wait(5)

        # Display fresh stdout / stderr
        sys.stdout.write(task.fresh_stdout())
        sys.stderr.write(task.fresh_stderr())

    # Display errors on failure
    if task.state == 'Failure':
        print("** Errors: %s" % task.errors[0])
        error_happened = True

finally:
    task.delete(purge_resources=True, purge_results=True)
    # Exit code in case of error
    if error_happened:
        sys.exit(1)

I also confirmed this script works when using the following connection method:

conn = qarnot.connection.Connection(client_token="xxxx-mytoken-xxxx")
ClemPi commented 3 years ago

Hello,

There is a typo in your samples.conf file.

Please use this one:

[cluster]
url=https://api.qarnot.com/

[client]
# This is your secret token, keep it safe
token=xxxx-mytoken-xxxx

Note the qarnot.com instead of quarnot.com.